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

Checking your account…

02.05 · Variables / Practice · 5 min

Update the ticket count

Three tickets. One gets used. Make your program keep track.

Activity 5 of 5 in Variables

All courses

JavaScript Basics / 02.05

Update the ticket count

Not started

Subtract a used ticket and check the remaining count.

More options
Rob starts with three available tickets, sets one used ticket aside, and checks that two remain.
Rob’s comic strip · Variables

Choose const and let deliberately

Work through 4 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)

4 steps · Saved work · Instant feedback

YOUR TURN

Update the ticket count.

There are 3 tickets and 1 gets used. Add an assignment that subtracts ticketsUsed from ticketsRemaining before the message is printed. The final message should say Tickets remaining: 2.

Expected output
Tickets remaining: 2

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
let ticketsRemaining = 3;
const ticketsUsed = 1;

// Update ticketsRemaining here.

console.log("Tickets remaining: " + ticketsRemaining);

Need a nudge?

Which value changes?

ticketsRemaining was declared with let because the available count changes. ticketsUsed can stay constant in this example.

Read an assignment right to left

Work out ticketsRemaining - ticketsUsed on the right, then store that result in ticketsRemaining on the left. You do not need another let.

Reveal a possible solution
One possible solution
example.jsjavascript · example
let ticketsRemaining = 3;
const ticketsUsed = 1;

// A used ticket is no longer available.
ticketsRemaining = ticketsRemaining - ticketsUsed;

console.log("Tickets remaining: " + ticketsRemaining);

An assignment updates an existing variable. Try starting with 5 tickets and using 2: your program should now say 3. The automated check covers the original 3-and-1 scenario; this extra experiment checks your reasoning.

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

Change a value, run your code, and check your prediction.