The Power Ascendant
EasyAcc. 96.4%
+20 XP 8
Doubling Up
In computing, powers of 2 (1, 2, 4, 8...) are everywhere. A while loop is the best tool for finding these values when you don't know exactly how many steps it will take.
The Assignment
Your function receives a parameter named limit.
- Declare a variable
powerOfTwoand initialize it to 1. - Write a
whileloop that continues as long aspowerOfTwois less than or equal tolimit. - Inside the loop, double the value of
powerOfTwoin each step. - After the loop, print the final value of
powerOfTwo.
01EXAMPLE 1
Input
limit = 50Output
64Explanation: 1->2->4->8->16->32->64. Since 64 > 50, it stops and prints 64.
Constraints
- Use a while loop.
- Print only the final result after the loop closes.
LoopsMath
JavaScriptSystem handles I/O — write your function only
Loading...
4 Hidden
Input Arguments
limit50
Expected Output
64
Click RUN to test your solution