Logo

dev-resources.site

for different kinds of informations.

Error in Javascript

Published at
5/28/2024
Categories
javascript
testing
errors
numbers
Author
dipesh_kumar
Categories
4 categories in total
javascript
open
testing
open
errors
open
numbers
open
Author
12 person written this
dipesh_kumar
open
Error in Javascript

Hey everyone, I was creating a simple program to give me output (sum of every digit of the value given by user) but the problem is, whenever user is giving a value more than 10 digits so the program gives wrong output. Here's the program:-

let n=566;
s=0;
while(n>9){
while(n>0){
r=n%10;
n=n/10>>0;
s+=r;
}
if(s<10){
console.log(s);
}else{
n=s;
s=0;
}
}

Input : 566
Output : 5+6+6= 17....1+7= 8
8 is final output

Input : 987654324567
Output : 9+8+7+6+5+4+3+2+4+5+6+6= 66....6+6= 12....1+2= 3
3 should be final answer but it's giving me 7

numbers Article's
29 articles in total
Favicon
Leetcode โ€” 3289. The Two Sneaky Numbers of Digitville
Favicon
Master Number Conversions with Ease: From Binary to Hexadecimal & More!
Favicon
Leetcode โ€” 2769. Find the Maximum Achievable Number
Favicon
Leetcode โ€” 3190. Find Minimum Operations to Make All Elements Divisible by Three
Favicon
Floating Point Representation (IEEE 754 ISSUE)
Favicon
Error in Javascript
Favicon
Million day archivio
Favicon
Exploring the Mystical Language of Numbers.
Favicon
How to Check if a Value is Within a Range of Numbers in JavaScript
Favicon
BINARY NUMBERS
Favicon
Prime Numbers โ€“ Definition with Examples
Favicon
Generator Random Numbers
Favicon
Binary representation of numbers
Favicon
Get all separate digits of a number (TypeScript)
Favicon
The fascinating diagonals of Pascal's Triangle
Favicon
Convert long numbers to string
Favicon
Patterns in the multiples of 2, 5, 10 and 3
Favicon
Your startup & the conspiracy of numbers
Favicon
Teaching the computers to write number names using JavaScript
Favicon
Learn Bash by making a game
Favicon
Convert Decimal to Binary for IOT Product With Vue.js
Favicon
Hunt some strange numbers with Python.
Favicon
Generate unique (non-repeating) random numbers
Favicon
Developer 2021 - Projections based from Stack Overflow's 2020 Developer Survey
Favicon
Learn Python: Numbers
Favicon
Find Valid Phone Numbers, Anywhere!
Favicon
Quick vim tips to generate and increment numbers
Favicon
What is the type of NaN?
Favicon
Recreating Excelโ€™s ISNUMBER in a Numbers Spreadsheet

Featured ones: