Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
$(document).ready(function() {
// Create chocolate cards
function createChocolateCards() {
chocolates.forEach((chocolate, index) => {
const card = $('<div>')
.addClass('chocolate-card')
.attr('id', `card-${index}`);
card.html(`
<h3>${chocolate.name}</h3>
<img src="${chocolate.image}" alt="${chocolate.name}">
<div class="details">
<p><strong>Calories:</strong> ${chocolate.calories}</p>
<p><strong>Description:</strong> ${chocolate.description}</p>
<p><strong>Ingredients:</strong> ${chocolate.ingredients}</p>
</div>
`);
$('#chocolateGrid').append(card);
});
}
// Toggle details functionality
function setupToggleDetails() {
$('#toggleDetails').click(function() {
$('.details').slideToggle();
$(this).text(function(i, text) {
return text === "Show Calories and Content"
? "Hide Calories and Content"
: "Show Calories and Content";
});
});
}
// Random sample functionality
function setupRandomSample() {
$('#randomSample').click(function() {
// Reset all cards to cream background
$('.chocolate-card').css('background-color', 'cream');
// Select random card
const randomIndex = Math.floor(Math.random() * chocolates.length);
const randomCode = Math.floor(Math.random() * 50) + 1;
// Highlight selected card
$(`#card-${randomIndex}`).css('background-color', 'yellow');
// Show alert with code
alert(`Your free sample code is: ${randomCode}\nShow this code to the cashier to receive your free ${chocolates[randomIndex].name} chocolate!`);
});
}
// Initialize all functionality
createChocolateCards();
setupToggleDetails();
setupRandomSample();
});