Question:
How can I show the result of the following function in a <div>
and not in an alert.
<script>
function suma (a,b){
var sum = a+b;
alert(sum);
};
suma(3,4);
</script>
Answer:
You could use the getElementById
to assign the value of the sum
function suma (a,b){
var sum = a + b;
document.getElementById('resultado').innerHTML = sum;
};
suma(3,4);
<div id="resultado"></div>