+ 2
How add function ewith plusing numbers? JS
I need function,that can plus user' s numbers. I did this function,but that function pluses strings. HELP ME!!! https://code.sololearn.com/WIC9CMlUDvwZ/?ref=app
3 Answers
+ 5
Akim Go
The window.prompt() can return either a string or a null. If user gives input the same input is returned in "string" format . If user don't enter anything then you get null.
Basically using + with strings will concat them.
You need to typecast the values read by prompt().
You can do as follows
let n =Number(prompt('enter no'));
in your case use:
document.write(Number(numberx) + Number(numbery));
prompt reference :
https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt
Typecasting lesson : https://javascript.info/type-conversions
+ 4
Akim Go my pleasure friendāŗš
Keep learning. I'm glad to see you coding š¤
+ 2
Thanks! You are my hero!