Forum Moderators: open

Message Too Old, No Replies

Javascript for loops?

         

mishging

7:09 pm on Apr 4, 2008 (gmt 0)

10+ Year Member



I'm new to javascript and have few questions...
I have to write a program to take an input of a number from a user. Then using a for loop print the times table of this number till the first 10 multiples. (For example: If the number inputted by the user is 4, your output onto the html page should be of the following format:
4 * 1 = 4

4 * 2 = 8

4 * 3 = 12

…..

…..

…..

4 * 9 = 36

4 * 10 = 40

httpwebwitch

7:14 pm on Apr 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi mishging,
I suspect that you're posting homework assignments into this forum. Am I right?

Based on my suspicion I'm not going to give you the answser outright, but I will get you started with a little fragment:

for(i=1;i<=10;i++){
document.write((num*i));
}

Do you have a javascript manual?

mishging

7:25 pm on Apr 4, 2008 (gmt 0)

10+ Year Member



Yep not going to lie, it is a homework assignment.
I don't have a javascript manual and my book doesn't have much on javascript either though

mishging

7:32 pm on Apr 4, 2008 (gmt 0)

10+ Year Member



ok so I have this so far..
<script type="text/javascript">
var num = prompt ("Enter a number", "");

for(i=1;i<=10;i++){
document.write((num*i));
}

</script>

httpwebwitch

8:17 pm on Apr 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is a decent Javascript Reference Manual [developer.mozilla.org] for you, courtesy of Mozilla.