Javascript arrow function with prompt.


Joined
Jul 12, 2020
Messages
2
Reaction score
0
let sum = () => {
a=prompt();
b=prompt();
return a+b;
}

console.log(sum());

I don't understand why the hell concatenate two numbers instead of sum them. Less understand why only a summary is a problem and multiply, extraction, dividing is OK. Can you help me please?
 
Ad

Advertisements

Joined
Nov 27, 2019
Messages
163
Reaction score
24
A prompt() returns a STRING not a number so a+b is a .concatenates then. Use Number() to change the string to a number.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top