dev-resources.site
for different kinds of informations.
Error in Javascript
Published at
5/28/2024
Categories
javascript
testing
errors
numbers
Author
dipesh_kumar
Author
12 person written this
dipesh_kumar
open
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
Leetcode โ 3289. The Two Sneaky Numbers of Digitville
read article
Master Number Conversions with Ease: From Binary to Hexadecimal & More!
read article
Leetcode โ 2769. Find the Maximum Achievable Number
read article
Leetcode โ 3190. Find Minimum Operations to Make All Elements Divisible by Three
read article
Floating Point Representation (IEEE 754 ISSUE)
read article
Error in Javascript
currently reading
Million day archivio
read article
Exploring the Mystical Language of Numbers.
read article
How to Check if a Value is Within a Range of Numbers in JavaScript
read article
BINARY NUMBERS
read article
Prime Numbers โ Definition with Examples
read article
Generator Random Numbers
read article
Binary representation of numbers
read article
Get all separate digits of a number (TypeScript)
read article
The fascinating diagonals of Pascal's Triangle
read article
Convert long numbers to string
read article
Patterns in the multiples of 2, 5, 10 and 3
read article
Your startup & the conspiracy of numbers
read article
Teaching the computers to write number names using JavaScript
read article
Learn Bash by making a game
read article
Convert Decimal to Binary for IOT Product With Vue.js
read article
Hunt some strange numbers with Python.
read article
Generate unique (non-repeating) random numbers
read article
Developer 2021 - Projections based from Stack Overflow's 2020 Developer Survey
read article
Learn Python: Numbers
read article
Find Valid Phone Numbers, Anywhere!
read article
Quick vim tips to generate and increment numbers
read article
What is the type of NaN?
read article
Recreating Excelโs ISNUMBER in a Numbers Spreadsheet
read article
Featured ones: