Nested loop

Joined
Feb 5, 2021
Messages
1
Reaction score
0
Trying to set up a nested loop with two numerical variables whereby the second variable gets added to the first for each iteration over a period of let’s say 5 loops. How do I go about that?
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
I should ask you what did you try and where are you having trouble, because this is a help site not a we do your work for you site, but this is not hard except for some cravats. Here is your code:
Code:
<body>
    <div id="demo"></div>
<script>
var x=1;
var y=1;
var sum = x + y;

for(var x=1; x<6; x++){
    for(var y=1; y<3; y++){
        var sum = x + y;
        document.getElementById("demo").innerHTML += "The number x is " + x + "The number y is " + y + "Their sum is " + sum + "<br>";
    }
}
</script>
</body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top