1
var bar=3;
while (bar>1) {
  console.log("ok"); 
  bar--; 
}

I am doing this course at codecademy, when I run the code this shows up in the console..

"ok"
"ok"
2

Why does it show a number?

When I insert additional code after the code, it doesn't. e.g.

var bar=3;
while (bar>1) {
    console.log("ok"); 
    bar--; 
}
var foo;
for (foo = 10; foo <12 ; foo++){ 
     console.log( "ok" ); 
}

I am an absolute beginner at this.

Rich
  • 43
  • 5
  • 4
    Using `++` and `--` return a value. This question might have some relevant information for you: http://stackoverflow.com/questions/3469885/somevariable-vs-somevariable-in-javascript – Sumner Evans May 10 '15 at 22:08

1 Answers1

0

When I am running the code you provided, 2 doesn't appears. It shouldn't appear anyway, as you are printing only the "ok" string and not a variable. Make sure than in the code you execute there is not a forgotten console.log .

cs04iz1
  • 1,737
  • 1
  • 17
  • 30