# Stuck on a Multiplication table with a for loop

So the challenge is to write a multiplication table with a for loop in JS

What I have figured out so far:

Alright so we know that the end number is 10x10
the begining is 1x1
where one number stays constant for 10 times
but is used to multiply with the other
that changed by 1+ each time
and must stop at the 10th one
so basicly it be like
1 x 1
1 x 1+
the keynumber here is 10
Examples how they a multiplication table should look like:

1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40

1 x 1 = 2
1 x 2 = 2
until the number of 10 x 10
which should result into 100

My code so far:

``````function (i, j) {
for
(i = 1; i++ ; i === 10 //write something that when i === 10 it
//it also tells j to increment by 1 and starts at 1 again(recursion?)
return i
//second number increase with 1 each time the loop runs
if i === 10; j++; j ===100 //function stops
}
document.write(i * j);
``````

Maybe I should use a double for loop but, I am not sure how to go proceed any suggestion/tip are appreciated

``````var i;
for (i = 0; i === 11; i++) {
for (j = 0; j === 11; j++)
}
``````

the double loop would be a good way to go

just be careful with details, remember to define all your variables, and be careful with the conditions of the loop, and that a return statement will exit the function

1 Like

Thanks Ieahleen I was thinking the same. Yeah for sure :3 alway’s double check

Be careful with that `document.write`, too - there are far better ways to do that.

If you like, I have a repl set up for just this task. It’s the framework of the double loops, building a multidimensional array - what you DO with that array is up to you. 1 Like

Is the output supposed to appear on a web page or in the browser console? So there needs to be a single space character between each num in a row?

You can actually accomplish this in a single for loop in O(n) time instead of O(n^2) time using a nested for loop or creating any arrays. When you figure it out with 2 loops, I will post my solution with a single loop.