HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JS Program to Condense a Number</h1> <script> var copyNum, result, remainder; var num = 8654; var userValue = num; while(num > 9) num = myCondense(num); function myCondense(a) { copyNum = a; remainder = 0; result = 0; while(copyNum != 0) { remainder = copyNum % 10; result += remainder; copyNum = Math.floor(copyNum / 10); } return result; } document.write("Single Digit of "+userValue+": "+num); </script> </body> </html>
OUTPUT
×

Save as Private