Sikau

JavaScript · Day 22 · about 30 min

Project: Times-table printer

Any table, any range.

Project time

Let's build a times-table printer: choose a number and a range, and it neatly prints the whole table. Then you'll extend it to print several tables at once.

The plan

  • Keep the number and range in variables so they're easy to change.
  • Loop through the range.
  • Build each line with a template literal: 7 x 3 = 21.
const table = 7;
const upTo = 3;
for (let i = 1; i <= upTo; i++) {
  console.log(`${table} x ${i} = ${table * i}`);
}

The rest of this lesson

  • Design the output firstexplain
  • From one table to manyexplain
  • How many lines?predict
  • One line of the tablefill
  • Step 1: one tablewrite code
  • Step 2: many tableschallenge
  • Badge quizquiz
  • Unit 4 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript