-2

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.

 var a = 399;  
 var b = 8;

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

When I run it I don't get any output.

What should I do in order to get the output?

The Onin
  • 5,068
  • 2
  • 38
  • 55

2 Answers2

2

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
The Onin
  • 5,068
  • 2
  • 38
  • 55
0

You can use alert() to create a popup in the browser, or you can use console.log() to output to the browser's console.

 var a = 399;  
 var b = 8;

 for (i = 0; i < 13; i++) {  
   a += b; 
 }
alert(a);
console.log(a);
Gavin
  • 4,365
  • 1
  • 18
  • 27