The Harshad Hunter
EasyAcc. 95.8%
+15 XP 5
The Joy-Giver
A Harshad Number is an integer divisible by the sum of its digits. Example: $18$ $ o 1 + 8 = 9 o 18$ is divisible by $9$.
The Assignment
Your function receives a parameter named num.
- Preserve a copy of the original number.
- Use a loop to calculate the sum of all digits in
num. - After the loop, check if the original number is divisible by that sum.
- Print "true" if it is, otherwise print "false".
01EXAMPLE 1
Input
num = 18Output
trueExplanation: 18 / (1+8) = 18 / 9 = 2.
Constraints
- Extract digits mathematically.
- Handle single-digit numbers.
MathLoopsDigits
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
num18
Expected Output
true
Click RUN to test your solution