Find Sum of Digits using While loop - JavaScript Tutorial 45

preview_player
Показать описание
JavaScript Tutorial 45 - Find Sum of Digits using While loop - JavaScript Tutorial 45

Example Code:
var num = 1234;
var lastDigit=0;
var sumOfAllDigits=0;

while(num!=0)
{
lastDigit = num % 10;
sumOfAllDigits = sumOfAllDigits + lastDigit;
num = parseInt(num/10);
}

Output:
10

=========================================

Follow the link for next video:
JavaScript Tutorial 46 - do while loop in JavaScript | JavaScript do while loop

Follow the link for previous video:
JavaScript Tutorial 44 - When to use while loop ?

=========================================

JavaScript Tutorials Playlist:-

=========================================
Watch My Other Useful Tutorials:-

jQuery Tutorials Playlist:-

jQuery UI Tutorials Playlist:-

Bootstrap Tutorials Playlist:-

=========================================

► Subscribe to our YouTube channel:

► Visit our Website:

=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial
Рекомендации по теме
Комментарии
Автор

SUBSCRIBE, SHARE & SUPPORT:
VISIT & LEARN AT FREE OF COST:

ChidresTechTutorials
Автор

Could you help me please, to find sum of digits in a number without using any loop

nizomiddin_shahina
Автор

Sir i have a question
Why didn't you use the Increment and Degree Meter Operator in this program?

AbdulBasit-expw
Автор

Sir, can you tell me without using parseInt, math.floor. how to sum some digits.

baluvasamsetti
Автор

Hello. Thanks for the lesson. Could you help me please, to find how to calculate product of digits of a number. for e.x. 1233 = 18. Thanks in advance.

teresaarakelyan
Автор

Sir how to count given numbers using while loop

manojkumarn
Автор

When i write this code for

At first operation
Lastdigit = num%10 shows 4 instead of 3... Can you please explain what is the cause

yugamer