In a script element in the body give the JavaScript code for
In a script element in the body give the JavaScript code for the following:
A for loop that loops 7 times and prints out: 0 1 2 3 4 5 6.
A while loop that loops 7 times and prints out: 2 4 6 8 10 12 14.
Hint: you can increment your iterator by more than just 1.
A do while loop that loops 6 times and prints out: 1 2 3 4 5 6.
A for loop that loops 7 times and prints out: 1 4 9 16 25 36 49.
Hint: use the Math.pow(x,2) method in the body of the loop.
Solution
<script>
var i;
 for (i = 0; i <=6; i++) {
 document.write(i);
 }
i=2
 while (i <= 14) {
 document.write(i);
 i = i + 2;
 }
i = 1;
 do {
 document.write(i);
 i++;
 }
 while (i < 6);
 for (i =1; i <=6; i++) {
 document.write(Math.pow(i,2));
 }
 </script>

