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?

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.