Why j is > 10 | Sololearn: Learn to code for FREE!

0

Why j is > 10

var i =10; var j =0; while (i > 0){ j++; i=i/2; };

1/27/2019 11:47:11 AM

Sara Hadj-Ali

3 Answers

New Answer

+1

Thank you ,i got it !

0

I haven't used JavaScript in a while, but I'm gonna guess that i is treated as a floating-point number instead of an integer. So, every time you execute the loop, the following happens: i j 10 0 5 1 2.5 2 1.25 3 0.625 4 . . . . . . You get the idea. The way around that problem is: i=Math.floor(i/2); inside the while loop.

0

var data =41; var o ={data : 42}; o.print =function(){ console.log(this.data); var print2 = function(){ console.log(this.data); } print2() ; }; var data =43 ; o.print() May you please look at the code below ,i didn't really understand the" this " notation and why the result we obtained is 42 43 ? Thank you souch 🙏🙏🙏🙏