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.

  1. Declare a variable powerOfTwo and initialize it to 1.
  2. Write a while loop that continues as long as powerOfTwo is less than or equal to limit.
  3. Inside the loop, double the value of powerOfTwo in each step.
  4. After the loop, print the final value of powerOfTwo.

01EXAMPLE 1

Inputlimit = 50
Output64

Explanation: 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
JavaScript
Loading...
4 Hidden

Input Arguments

limit50

Expected Output

64

Click RUN to test your solution