Day 35: Sum of all digits of a Number of 100DaysCodingChallenge

Hello all, 

I have started the 100 days of coding challenge to improve my programming skills..

Today is the Day35 of 100DaysCodingChallenge for 

Sum of all digits of a Number input Numbers taken by the user.

Code : 

let n = prompt("Enter a Number : ");
let sum = s = 0;
let n1 = n;
while (n > 0) {
  s = n % 10;
  sum = sum + s;
  n = Math.floor(n/10);
}
console.log("The Sum of all digits of Number", n1, "is :", sum);

Output :     

 





Happy Coding:)

Comments

Popular posts from this blog

Day 100: Date Time to Number of 100DaysCodingChallenge

Day 64: Pattern using loops of 100DaysCodingChallenge

Day 20: Positive Number of 100DaysCodingChallenge