I am a complete novice at programming who is following a course in JavaScript as my first language.
Our current task is to use the any of the following:
forloopwhileloop- Nesting
document.write
to create the following result (without the additional enter):
1
2 3
4 5 6
7 8 9 10
11 12 13 14
The last number in the sequence must be user-defined.
I am able to produce the following:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
using edit: please note that the var "rows" is misleading (see bold text above):
var rows = parseInt(prompt("choose end number"))
var i
var j
for (i = 1; i <= rows; i++)
{
for(j=1; j<=i; j++)
{
document.write(j + " ");
}
document.write("<br>");
}
But I am not able to create something that breaks and then continues the sequence on the next line.
If you have the time, could you also give me an explanation of the code you post in terms of how the computer processes it and why it works?