While Loops - Output Repeating the Last Result Twice


#1

Hi. I have an output question. I am working on wile loops. It works for the most part, but the last result gets repeated twice. This has happened to be before on other exercise. Am I doing something weird with my brackets?

CODE:
var x = 1;
while (x <= 5) {
console.log(x);
x++;
}

OUTPUT:
1
2
3
4
5
5


#2

The console always prints the last value. There's nothing wrong with your code!


#3

it prints it twice. there isn't a way to get rid of it?


#4

I don't think so. For more information check out @haxor789's explanation on this post.


#5

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