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

Checking your account…

12.01 · Loop challenges & review / Practice · 7 min

Generate a multiplication table

Rob needs ten rows that follow the same pattern. Generate each row from the inputs.

Activity 1 of 7 in Loop challenges & review

All courses

JavaScript Basics / 12.01

Generate a multiplication table

Not started

Turn one changing multiplier into ten useful lines.

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 compares 1 x 5 = 5, 2 x 5 = 10 and 3 x 5 = 15, with one additional group of five dots per row.
The multiplier changes from 1 to 2 to 3; each row adds another group of five. The challenge continues through multiplier 10.

Generate a multiplication table with a loop

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

Generate a multiplication table

Use a for loop to print the multiplication table for number = 5, from multiplier 1 through 10. Keep the header and row format. Calculate product from both values; do not hard-code ten rows.

Expected output
Multiplication Table for 5:
1 x 5 = 5
2 x 5 = 10
3 x 5 = 15
4 x 5 = 20
5 x 5 = 25
6 x 5 = 30
7 x 5 = 35
8 x 5 = 40
9 x 5 = 45
10 x 5 = 50

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 number = 5;
console.log("Multiplication Table for " + number + ":");
for (let multiplier = 1; multiplier <= 10; multiplier++) {
  const product = number;
  console.log(multiplier + " x " + number + " = " + product);
}

Need a nudge?

Separate the changing value

The chosen number stays five. multiplier changes from one through ten. Each row needs the product of those two values.

Calculate before formatting

Keep product numeric. Join it into the display text after doing the multiplication.

Reveal a possible solution
One possible solution
example.jsjavascript · example
const number = 5;
console.log("Multiplication Table for " + number + ":");
for (let multiplier = 1; multiplier <= 10; multiplier++) {
  const product = multiplier * number;
  console.log(multiplier + " x " + number + " = " + product);
}

Try number = 0, 1 and 7. The table always has ten product rows. Explain why changing number changes every product without changing the loop header.

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

Calculate each product from the current counter and the chosen number.