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 :: sequelize include only 
Javascript :: vue on click router push not working 
Javascript :: DataTypes Time sequelize 
Javascript :: jquery set html of element 
Javascript :: javascript sum array of objects by key 
Javascript :: putting a loop into an array javascript 
Javascript :: how to clear local storage 
Javascript :: express search query 
Javascript :: how to change text to italic in javascript 
Javascript :: javascript hard reload 
Javascript :: js get option value 
Javascript :: vue dynamic component props 
Javascript :: discord bot playing game 
Javascript :: react native scrollable 
Javascript :: check if type is blob javascript 
Javascript :: how to get the url of a page in javascript 
Javascript :: axios get error response message 
Javascript :: firebase cloud functions schedule function run time 
Javascript :: scroll element by javascript 
Javascript :: csrf token in js laravel 
Javascript :: flip a coin javascript 
Javascript :: livewire set model with javascript 
Javascript :: convert array to object javascript 
Javascript :: mocha timeout 
Javascript :: how to install react router dom 
Javascript :: regex to indentify url 
Javascript :: javascript infinite parameters 
Javascript :: axios post with header 
Javascript :: react fetch url 
Javascript :: javascript index of min value in array 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =