To get the smallest power of two using while loop


#1

https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/web-dev-intermediate-javascript-practice/lessons/intermediate-javascript-coding-challenge/exercises/fix-the-broken-code
In exercise 5, Fix The Broken Code! I can’t understand the while loop here.
image
image
How does the code here work to get the smallest power of two?
Why does it use j = j * 2; ? By j = j * 2, doesn’t it mean j times 2? not 2 n, power of two?

Thanks for your explanation in advance.


#2

exponentiation is repeated multiplication, and there you have multiplication in a loop

you might want to carry out the operations yourself in your head/on paper, or add prints to get information out of your program about what happens


#3

Got it now, thank you so much. :grinning: