+ 1

Can someone explain this code to me?

var i = 3; var k = 0; for(var j = 0; j<Math.pow(i,3);j++){ k++; //k=k*10; } document.write(k);

18th May 2017, 4:16 PM
Chandra Wibowo
Chandra Wibowo - avatar
4 Respostas
+ 4
OK.. initially the value of i=3 so by executing the condition Math.pow(i,3) the limit value become 27 (3^3) then the working of loop is Just as like work of for loop.. Don't get confused with the statement //k=k*10 it's Jus a statement so it won't consider for execution.. so after completing the loop the value become 27
18th May 2017, 4:27 PM
Vignesh
Vignesh - avatar
+ 2
26??
18th May 2017, 4:21 PM
Vignesh
Vignesh - avatar
0
@Vignesh No 27
18th May 2017, 4:23 PM
Chandra Wibowo
Chandra Wibowo - avatar
0
Oh wait. I was so confused I get 9 from pow(3,3). My mistake. Thank you @Vignesh.
18th May 2017, 4:32 PM
Chandra Wibowo
Chandra Wibowo - avatar