+ 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

8th Oct 2019, 7:49 AM
Akim Go
Akim Go - avatar
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
8th Oct 2019, 8:35 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
+ 4
Akim Go my pleasure friendā˜ŗšŸ™ Keep learning. I'm glad to see you coding šŸ¤“
8th Oct 2019, 8:38 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
+ 2
Thanks! You are my hero!
8th Oct 2019, 8:36 AM
Akim Go
Akim Go - avatar