+ 13
JAVASCRIPT CHALLENGE QUESTION
Someone help. Why is the output 9: var x = 6, y = 0; while (x>0 & & y<6) { x--; y+=x; } document.write(y)
6 ответов
+ 15
in first iteration
x :5
y: 5
condition x >0 & & y <6 // true
second iteration
x: 4
y: 9
condition x >0 & & y<6 // false because 9 >6
+ 9
your while loop executes twice.
first 6 is decremented by 1, then added to y (which is 0). y now equals 5.
the second time the loop goes through, it adds 4 to y and stops because y is now greater than 6.
y is now 9, your loop stops and writes 9
+ 8
Thanks men.
I did not read it properly 🤦🏽♂️
+ 4
First condition
X-- (6-1=5)
Y+x (5+0=5)
Second condition
X--(5-1=4)
Y+x(5+4=9)
So output will be 9
+ 3
Thanks Guys!
Well understood... 👍🏼 🌼