Question: Write a function named sumOfDigits that accepts a positive integer and returns the sum of its digits. example: sumOfDigits(8675309) ==> 38 sumOfDigits(111) ==> 3 Write
Write a function named sumOfDigits that accepts a positive integer and returns the sum of its digits.
example: sumOfDigits(8675309) ==> 38 sumOfDigits(111) ==> 3
Write a function named isHarshad that accepts an integer and returns true if is a Harshad number, false otherwise. isHarshad must call sumOfDigits.
example: alert(isHarshad(8675309)) ==> false alert(isHarshad(111)) ==> true
I already have the sumOfDigits, but I keep getting all true or all false when I run the isHarshad function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
