PDA

matz0rz
Mar 1st, 2013, 06:52 AM
I'm not the type to ask for help... That being said, PLEASE HELP ME! I need to code a multiplication table from 1 to 9 using for loops. I've been trying to wrap my head around it for 2 hours now. Please help me, thank you!

PS: You don't need to write the whole code for me, just point me in the right direction!

Much appreciated !

Write a program called TimeTable to produce the multiplication table of 1 to 9 as shown using two nested for-loops:

* | 1 2 3 4 5 6 7 8 9
-------------------------------
1 | 1 2 3 4 5 6 7 8 9
2 | 2 4 6 8 10 12 14 16 18
3 | 3 6 9 12 15 18 21 24 27
4 | 4 8 12 16 20 24 28 32 36
5 | 5 10 15 20 25 30 35 40 45
6 | 6 12 18 24 30 36 42 48 54
7 | 7 14 21 28 35 42 49 56 63
8 | 8 16 24 32 40 48 56 64 72
9 | 9 18 27 36 45 54 63 72 81

By nested for-loops, he means: a for loop within a for loop.

Example:

for(var x = 0; x < 9; x++){
document.writeln("x" + "x" + "x" + "x" + "x" + "x" + "x" + "x" + "x");
for(var y = 0; y < 9; y++){
document.writeln("y" + "y" + "y" + "y" + "y" + "y" + "y" + "y" + "y");
}
}

Old Pedant
Mar 1st, 2013, 07:51 AM
See Rule 1.5 in http://www.codingforums.com/rules.htm

That being said...

*IF* you show that you have made a reasonable attempt at solving the problem, and you just have one or two kinks to be worked out, you will surely get some help.

But don't expect somebody to write it for you when you haven't go beyond the current stage.

Truly, you just need to *THINK* about what it is you need to do:

For each outer loop, what will you produce? Answer: The row number for that loop (1 through 9) and the vertical bar after it.

For each inner loop, what will you produce? Answer: One product, resulting from the multiplication of the two loop counters.

HINT: You will put in the first two rows--the list of number 1 to 9 with the horizontal line underneath--by hand. Nothing to do with the loops.

Old Pedant
Mar 1st, 2013, 07:53 AM
And by the by, 2 hours in programming time is nothing. Granted that an experienced coder could do this in 2 minutes, there are many many many programming problems that take 2 days, 2 weeks, 2 months, 2 years. Yes, I've been involved in projects where it took us nearly 2 years to get to the point where we could see real results.

If you don't have more than 2 hours of patience, then programming is probably not the career for you.

matz0rz
Mar 1st, 2013, 07:59 AM
And by the by, 2 hours in programming time is nothing. Granted that an experienced coder could do this in 2 minutes, there are many many many programming problems that take 2 days, 2 weeks, 2 months, 2 years. Yes, I've been involved in projects where it took us nearly 2 years to get to the point where we could see real results.

If you don't have more than 2 hours of patience, then programming is probably not the career for you.

It's do on Monday! I love programming man. You got me wrong!
Thanks for the advice though :)

Philip M
Mar 1st, 2013, 08:46 AM
matz0rz -

Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.