When concatenating a string with the variables, the operations are not carried out correctly. When the sum is made, when putting the string "Sum", the variables are concatenated, instead if I remove them, they add up fine.
function mates(){
var result = document.getElementById("result");
var num1 = parseInt(prompt("Numero 1"));
var num2 = parseInt(prompt("Numero 2"));
result.innerHTML = "Suma"+num1 + num2+ "<br />";
result.innerHTML += "Resta" +num1 - num2;
}
<html>
<head></head>
<body>
<p>
<input id="bot1" type="button" value="F1" onclick="mates()" />
</p>
<p id="result"></p>
</body>
</html>
Have you tried putting parentheses?
With the parentheses you indicate the priority of the operations.
There is no need to concatenate like that, use template strings instead .
Staying this way
br
can be inside the same bakticksHere you can review its support which is broad across browsers.
And here the source where you can read more about it