Help me make my code correct | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help me make my code correct

It gives me an incorrect number as a result https://code.sololearn.com/WFC6w8sk1twn/?ref=app

7th Mar 2020, 1:57 PM
Sergiy Havryliuk
Sergiy Havryliuk - avatar
6 Answers
+ 3
It gives correct answer. It is just that the input is taken as a string so 'z' is added as a string to the result. If I give 'z' as 3 then according to your code, it will return 213 since 6+15=21 and 3 is concatenated to it. Instead of passing just 'z', do parseInt(z).
7th Mar 2020, 2:08 PM
Avinesh
Avinesh - avatar
+ 3
document.write(plus(6, 15, parseInt(z)));
7th Mar 2020, 2:31 PM
Avinesh
Avinesh - avatar
+ 1
Thanks, Avinesh !
7th Mar 2020, 2:48 PM
Sergiy Havryliuk
Sergiy Havryliuk - avatar
+ 1
Sergiy Havryliuk you're welcome.
7th Mar 2020, 2:48 PM
Avinesh
Avinesh - avatar
+ 1
You could also do something like: var z = Number(prompt("Enter the last number:")); it'll take the user input and convert it from a string to int and store it as an int to the variable z.
8th Mar 2020, 12:04 AM
Shaxes
Shaxes - avatar
0
And how to make z like a number? I want to add these 3 nubmers
7th Mar 2020, 2:30 PM
Sergiy Havryliuk
Sergiy Havryliuk - avatar