thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

04.05 · Numbers / Practice · 8 min

Total two diner orders

The diner has three prices and two different orders. Make the same named prices work for both customers.

Activity 5 of 8 in Numbers

All courses

JavaScript Basics / 04.05

Total two diner orders

Not started

Complete the original burger, fries and milkshake assignment with named prices and two customer totals.

More options

Your lesson progress

Reading & walkthrough: not startedGuided practice: not started

Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

Rob checks a diner tray with a burger, fries and shake, totals a second order, and compares two receipts.
Rob’s comic strip · Numbers

Calculate both diner orders from named prices

Work through 3 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

3 steps · Saved work · Instant feedback

YOUR TURN

Total two diner orders

Use the original prices: hamburger 2.85, fries 2.15, milkshake 2.45. Customer 1 orders one of each. Customer 2 orders three burgers and one milkshake. Fix both totals using the named prices, then print customer1Total and customer2Total in that order. Expected output: 7.45 and 11.

Expected output
7.45
11

Keep the starting inputs. Print these lines in this order, without extra output.

Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Work in VS Code instead

Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.

Code example
example.jsjavascript · example
const hamburger = 2.85;
const fries = 2.15;
const milkshake = 2.45;

let customer1Total = hamburger;
let customer2Total = hamburger + milkshake;

console.log(customer1Total);
console.log(customer2Total);

Need a nudge?

Read each order separately

The first customer needs all three named prices. The second does not order fries.

Three burgers share one price

Multiply hamburger by 3, then add milkshake. Do not replace the variable names with hard-coded totals.

Reveal a possible solution
One possible solution
example.jsjavascript · example
const hamburger = 2.85;
const fries = 2.15;
const milkshake = 2.45;

let customer1Total = hamburger + fries + milkshake;
let customer2Total = 3 * hamburger + milkshake;

console.log(customer1Total);
console.log(customer2Total);

This adapts your original practical assignment and its submission into one activity. When signed in, submit here instead of copying a JSFiddle link. Try hamburger = 3, fries = 2, and milkshake = 4: the totals should become 9 and 13. Some decimal inputs can show a tiny floating-point representation difference; that is separate from which items belong in an order. Instructors can review how you built each expression; the check compares only the printed output.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Named prices make a calculation easier to read and change.