Skip to content

Instantly share code, notes, and snippets.

@happychait
Created March 30, 2012 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happychait/2250787 to your computer and use it in GitHub Desktop.
Save happychait/2250787 to your computer and use it in GitHub Desktop.
Finds single digit sum of a number.
singleDigitSum = function( number){
if(number % 9 === 0){
return 9;
}
else{
return number % 9;
}
};
do{
var number = prompt("Enter number to find single digit sum.Enter 'q' to quit.");
if(number.length > 0 && isNaN(number)===false)
alert("Single digit sum of " + number + " is: "+ singleDigitSum(number));
else if(number!== 'q')
alert("Please enter a numeric value.");
} while(number !== 'q');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment