oliver Bergman oliver Bergman - 12 days ago 4
Javascript Question

Javascript for loop add a number x times

I need some help with this problem.

Exercise:


  • Use a for-loop to increment 399 with the value 8, 13 times.



My Code so far.

When i run it I get Error, could any one help me in the right direction?

var a = 399;
var b = 8;

for (i = 0; i < 13; i++) {
a += b;
}
ANSWER = a;

Answer

Your code is fine, and in order to output the result, add this after the for loop:

Display in browser console

console.log(a);

Display a blocking alert

alert(a);

Here's a demo with alert():

var a = 399;
var b = 8;

for (i = 0; i < 13; i++) {  
  a += b; 
}

alert(a); // output it

Comments