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?
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
A prompt() returns a STRING not a number so a+b is a .concatenates then. Use Number() to change the string to a number.
 

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

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top