Im very beginner, and I know we must be carefull with plus sign because sometimes its happen, it concatenate instead of adding. Can someone help with the code bellow? Wy is it concatenating?
var num1 = prompt('Enter a number')
var operator = prompt('Enter a operator')
var num2 = prompt('Enter another number')
var gettingResult = function (num1, operator, num2) {
var result = 0
num1 = parseFloat(num1)
num1 = parseFloat(num2)
if (operator == '*'){
result = num1 * num2
} else if (operator == '+'){
result = num1 + num2
} else if (operator == '-'){
result = num1 - num2
} else if (operator == '/'){
result = num1 / num2
} else {
document.write('Error on input its not a operator')
}
return result
}
document.write(gettingResult(num1, operator, num2))