Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sum of digits in a whole number javascript

sum = 0;
while (value) {
    sum += value % 10;
    value = Math.floor(value / 10);
}
Comment

javascript sum digits in string of numbers

const sumDigits = num => num.toString().split('').map(Number).reduce((a,b) => a + b);
//usage: mySum=sumDigits(myNum); console.log(sumDigits(1234)) output: 10
Comment

javascript Program for Sum of the digits of a given number

<script>
 
// Javascript program to compute sum of digits in
// number.
 
/* Function to get sum of digits */
function getSum(n)
{
    var sum = 0;
    while (n != 0) {
        sum = sum + n % 10;
        n = parseInt(n / 10);
    }
    return sum;
}
 
// Driver code
var n = 687;
document.write(getSum(n));
 
</script>
Comment

js sum digits

// Sum of all the digits of a number in Javascript
const num = 1245,
    sum = num
        .toString()
        .split('')
        .map(Number)
        .reduce((a,b) => a + b);
console.log(sum); // 12
Comment

PREVIOUS NEXT
Code Example
Javascript :: create csv file javascript 
Javascript :: find last element in array nodejs 
Javascript :: change title react 
Javascript :: Radom String in Javascript 
Javascript :: uploading file with fetch 
Javascript :: jsonobject in variable 
Javascript :: array length javascript 
Javascript :: supertest multipart/form-data 
Javascript :: js generate random string of length 
Javascript :: js get element by index 
Javascript :: js remove value input 
Javascript :: set timeout for loop 
Javascript :: how to pass the data from one page to another in javascript 
Javascript :: Map in Javascript in LWC 
Javascript :: uselocation react 
Javascript :: new date parameters javascript 
Javascript :: read xlsx file in angular 5 
Javascript :: as it does not contain a package.json file. react 
Javascript :: object traversal javascript 
Javascript :: js list pf objects 
Javascript :: close div when click outside angular 7 
Javascript :: update data firestore 
Javascript :: javascript element height 
Javascript :: get window width 
Javascript :: print random string from an array to screen in javascript 
Javascript :: add tailwind to vue 
Javascript :: image upload react 
Javascript :: change value of variable javascript 
Javascript :: preview upload image jquery 
Javascript :: how to unban in discord js 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =