One of my recent challenges involved creating a calculator using JavaScript.
The main issue I encountered was figuring out how to find the sum of 2 arrays. The first number, 33, is saved to an array called num1, and the second number, 99, is saved to an array called num2. For example, if we add 33 and 99 (33+99 = ?), the result should be 132.
After experimenting, I came up with the following code snippet. However, the total returns in a concatenated format (1,3,5,3) instead of the desired numerical sum.
const calculate = (n1,n2) => {
let result = ""
if (n1.length > 0 ){
result = n1 + n2
}
return result
}
v.push(calculate(num1, num2))
document.getElementById("answer").innerHTML = v