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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thanksgiving Meal</title>
</head>
<body>
<h1 class="greeting">Thanksgiving Meal Details</h1>
<p class="fullMeal"></p>
<p class="priceInfo"></p>
<p class="calorieInfo"></p>
<p class="caloriesFrom"></p>
<script>
const thanksgivingMeal = {
starter: {
fruit: "honeydew melon",
wine: "moscato",
calories: 180
},
entree: {
meat: "Turkey",
alt: "Stuffed green peppers",
vegetables: {
potatoes: "Creamed mashed potatoes",
greens: "French beans",
salad: "Radicchio"
},
sides: {
bread: "garlic bread rolls",
pasta: "Macaroni and Cheese"
},
calories: 450
},
dessert: {
ice_cream: "pumpkin-vanilla",
cake: "frosted pumpkin pie",
calories: 300
},
total_cost: 25.0,
senior_discount: 0.10,
prettyPrint: function() {
return `Starter: ${this.starter.fruit} and ${this.starter.wine}\n` +
`Entree: ${this.entree.meat} or ${this.entree.alt} with ${this.entree.vegetables.potatoes}, ${this.entree.vegetables.greens}, and ${this.entree.vegetables.salad}, served with ${this.entree.sides.bread} and ${this.entree.sides.pasta}\n` +
`Dessert: ${this.dessert.ice_cream} ice cream and ${this.dessert.cake}`;
},
totalPrice: function(isSenior) {
return isSenior ? this.total_cost * (1 - this.senior_discount) : this.total_cost;
},
totalCalories: function() {
return this.starter.calories + this.entree.calories + this.dessert.calories;
},
caloriesFrom: function(indicator) {
switch(indicator) {
case 'starter':
return this.starter.calories;
case 'entree':
return this.entree.calories;
case 'dessert':
return this.dessert.calories;
default:
return 0;
}
}
};
// Displaying the results
document.querySelector(".fullMeal").textContent = thanksgivingMeal.prettyPrint();
document.querySelector(".priceInfo").textContent = `Total Price (Senior): $${thanksgivingMeal.totalPrice(true).toFixed(2)}`;
document.querySelector(".calorieInfo").textContent = `Total Calories: ${thanksgivingMeal.totalCalories()}`;
document.querySelector(".caloriesFrom").textContent = `Calories from Entree: ${thanksgivingMeal.caloriesFrom('entree')}`;
// Debugging with console.log
console.log(thanksgivingMeal.prettyPrint());
console.log(`Total Price (Senior): $${thanksgivingMeal.totalPrice(true).toFixed(2)}`);
console.log(`Total Calories: ${thanksgivingMeal.totalCalories()}`);
console.log(`Calories from Entree: ${thanksgivingMeal.caloriesFrom('entree')}`);
</script>
</body>
</html>