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.

  1. Preserve a copy of the original number.
  2. Use a loop to calculate the sum of all digits in num.
  3. After the loop, check if the original number is divisible by that sum.
  4. Print "true" if it is, otherwise print "false".

01EXAMPLE 1

Inputnum = 18
Outputtrue

Explanation: 18 / (1+8) = 18 / 9 = 2.

Constraints

  • Extract digits mathematically.
  • Handle single-digit numbers.
MathLoopsDigits
JavaScript
Loading...
3 Hidden

Input Arguments

num18

Expected Output

true

Click RUN to test your solution