What will be displayed in the alert box at the end of script execution? var y = 0; for (x = 0; x <= 5; x++, y = y + 50) { y = y + 10; } alert("The value of y is :" + y);
Answers
Answered by
0
The value of y is 360 .
EXPLANATION:
The given code is a for loop which will begin with variable x=0 and loop will execute until x<=5.
for (x = 0; x <= 5; x++, y = y + 50)
{ y = y + 10; }
Initially x=0, y=0, enters loop, first time, y=50,x=1
Then y=50+10=60. Now loop will start and at each step x is incremented by 1 and y is incremented two times (y=y+50 and y=y+10)
X=1,y= 60+50=110
Y=110+10=120
X=2, y= 120+50=170
Y=170+10=180
X=3,y=180+50=230
Y=230+10=240
X=4, y= 240+50=290
Y=290+10=300
X=5, y=300+50=350
Y=350+10=360
Similar questions
English,
5 months ago
Math,
5 months ago
Computer Science,
11 months ago
Computer Science,
11 months ago
Math,
1 year ago
Math,
1 year ago