+ 3

Here's another. It outputs 12. Need detailed clarification, please.

var a = 0; for ( k = 1; k <= 2; k = k + 1) { for ( i = 0; i <= 5; i + 1) {} a++ document.write (a); }

22nd Feb 2018, 6:21 PM
Briaה‎
1 Réponse
+ 3
Because the code "document.write" is still inside of the first for loop.So it will not add the variable "a" as 1+1=2. It will only add the variable "a" as 1+1=11. So you should move the "document.write" command outside the for loop(after the brace). In addition there is some additional errors .You should replace the text "i +1" in your code to "i =i+1". put ";" after the code "a++". Then run the code.It will result the output as 2.
11th Mar 2018, 3:20 PM
Arun B R
Arun B R - avatar