Read the question, write JavaScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read n and log its times table from 1 to 10.
Each line reads n x i = result with a single space around each symbol.
Input. One line: an integer n.
Output. Ten lines, e.g. 3 x 1 = 3 up to 3 x 10 = 30.
Constraints
- Loop condition i <= 10 (not i < 10) to include ten.
Examples
Input
3
Output
3 x 1 = 3 3 x 2 = 6 3 x 3 = 9 3 x 4 = 12 3 x 5 = 15 3 x 6 = 18 3 x 7 = 21 3 x 8 = 24 3 x 9 = 27 3 x 10 = 30
Hint
- for (let i = 1; i <= 10; i++) { ... }
- A template literal reads cleanly: `${n} x ${i} = ${n * i}`.
Show correct code
Peek only after you have tried. You can still Check your own version.
const n = Number(readLine());
for (let i = 1; i <= 10; i++) {
console.log(`${n} x ${i} = ${n * i}`);
}
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.