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.
- Initialize
countto 0. - If
numis negative, convert it to positive. - Use a loop to peel off each digit of
num. - If a digit is exactly 7, increment
count. - After searching all digits, print the final
count.
01EXAMPLE 1
Input
num = 707Output
2Explanation: Two 7s found.
02EXAMPLE 2
Input
num = 123Output
0Explanation: No 7s.
Constraints
- Extract digits mathematically (no strings).
- Use a while loop.
MathLoopsDigits
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
num707
Expected Output
2
Click RUN to test your solution