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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!