+ 1

where is wrong !!! ??? {javascript}

/*global alert,prompt*/ function multiplicationnumber(a, b) { "use strict"; return a * b; } function collectnumbers(a, b) { "use strict"; return a + b; } function subtractnumbers(a, b) { "use strict"; return a - b; } function divisionnumbers(a, b) { "use strict"; return a / b; } var number1 = prompt("pleease enter the first number!!!"), number2 = prompt("pleease enter the second number!!!"), mark = prompt("please enter operation type"); if (mark === "+") { alert(collectnumbers(number1, number2)); } else if (mark === "*") { alert(multiplicationnumber(number1, number2)); } else if (mark === "-") { alert(subtractnumbers(number1, number2)); } else if (mark === "/") { alert(divisionnumbers(number1, number2)); } for * and / and - operate normally but for + the number 1 and number2 are string and do not combine but write together where is wrong !!! ???

22nd Jan 2019, 4:17 PM
program programing
program programing - avatar
2 odpowiedzi
+ 5
+ is also used to concatenate two strings together, so number1 and number2 aren't cast into integers like with the other operators. Use parseInt() to parse a string into an int. var number1 = parseInt(prompt("pleease enter the first number!!!")); var number2 = parseInt(prompt("pleease enter the second number!!!"));
22nd Jan 2019, 4:34 PM
Zen
Zen - avatar
0
thank you zen :) it's right
22nd Jan 2019, 4:43 PM
program programing
program programing - avatar