+ 1
Help me make my code correct
It gives me an incorrect number as a result https://code.sololearn.com/WFC6w8sk1twn/?ref=app
6 ответов
+ 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).
+ 3
document.write(plus(6, 15, parseInt(z)));
+ 1
Thanks, Avinesh !
+ 1
Sergiy Havryliuk you're welcome.
+ 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.
0
And how to make z like a number? I want to add these 3 nubmers