Mini Project 1: The Pizza Party Calculator

Grade 3, page 9 of 11. A one-minute read.

You're throwing a party. Each pizza has 8 slices, and each guest will eat 3 slices (realistically, more, but let's be optimistic). How many pizzas do you need to order, and how many slices will be left over?

pizza.js
const guests = 13;
const slicesPerGuest = 3;
const slicesPerPizza = 8;
const pricePerPizza = 85;

const slicesNeeded = guests * slicesPerGuest;
const pizzasToOrder = Math.ceil(slicesNeeded / slicesPerPizza);
const totalSlices = pizzasToOrder * slicesPerPizza;
const leftovers = totalSlices - slicesNeeded;
const cost = pizzasToOrder * pricePerPizza;
const costPerGuest = cost / guests;

console.log(`🍕 Pizza Party Planner 🍕`);
console.log(`Guests: ${guests}`);
console.log(`Slices needed: ${slicesNeeded}`);
console.log(`Pizzas to order: ${pizzasToOrder}`);
console.log(`Leftover slices: ${leftovers}`);
console.log(`Total cost: $${cost}`);
console.log(`Cost per guest: $${costPerGuest.toFixed(2)}`);
console.log(`Enough for seconds? ${leftovers >= guests}`);

It prints

🍕 Pizza Party Planner 🍕
Guests: 13
Slices needed: 39
Pizzas to order: 5
Leftover slices: 1
Total cost: $425
Cost per guest: $32.69
Enough for seconds? false

Why Math.ceil? Because 39 slices ÷ 8 = 4.875 pizzas, and the pizza shop won't sell you 0.875 of a pizza. You must round up, or someone goes hungry. (And a hungry guest is a grumpy guest.)

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning