0

This code have some kind of error. It does not add numbers. Just display them without adding them. Can somebody explain why?

function bankAccounts(name, coin) { name = prompt("Name, please"); var a = prompt("On your first account you have ", ''); var b = prompt("and on another you have ", ""); coin = a + b; alert( "So " + name + " in total, you have " + coin + " coins."); } bankAccounts()

6th Jul 2018, 9:55 AM
Smajil Alisic
Smajil Alisic - avatar
2 ответов
+ 1
prompt() returns a string you have to turn it into an int or float e.g. var a = parseInt(prompt("On your first account you have")); Same with string -> float but parseFloat()
6th Jul 2018, 10:00 AM
TurtleShell
TurtleShell - avatar
0
Thanks! I have to learn a lot, there are more commands then I thought.
6th Jul 2018, 10:07 AM
Smajil Alisic
Smajil Alisic - avatar