The Lucky Seven

EasyAcc. 98.1%
+15 XP 5

Finding Sevens

In this mission, you must extract every digit of a number and count how many of them are 7s.

The Assignment

Your function receives a parameter named num.

  1. Initialize count to 0.
  2. If num is negative, convert it to positive.
  3. Use a loop to peel off each digit of num.
  4. If a digit is exactly 7, increment count.
  5. After searching all digits, print the final count.

01EXAMPLE 1

Inputnum = 707
Output2

Explanation: Two 7s found.

02EXAMPLE 2

Inputnum = 123
Output0

Explanation: No 7s.

Constraints

  • Extract digits mathematically (no strings).
  • Use a while loop.
MathLoopsDigits
JavaScript
Loading...
3 Hidden

Input Arguments

num707

Expected Output

2

Click RUN to test your solution