Random number 4 at the end of output


#1


Hi, i have no idea but when i run my code (look bellow) its works just fine except at the end of output is number "4". Can anybody please tell me why ? :slight_smile: thx


for (i=0;i<5;i++){
    console.log("this is  for");
    }
    
var stop = 0;   
while (stop <5){
    console.log("this is while");
    stop++
    }
var stop2 = 0;   
do {
    console.log("this is  do while");
    stop2++
    } while (stop2<5);

output :

this is for
this is for
this is for
this is for
this is for
this is while
this is while
this is while
this is while
this is while
this is do while
this is do while
this is do while
this is do while
this is do while
4


#2

@shakatroll

It is the Javascript interpreter which is running in this course-environment,
it display's the last non-displayed action...
( in your case the result of stop2++ )

You will also encounter this, when you are doing a return-statement
as last action...
You could counter this by using a
console.log( " " ); as last statement....

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.