-1
Is it possible for someone to answer this question? It should be simple, but it’s breaking my head. The code below is not running. Only when I remove the variables Width and Height from within the functions
function mostrarAreaAlert() {
var largura = prompt("Digite a largura");
largura = parseFloat(largura);
var altura = prompt("Digite a altura");
altura = parseFloat(altura);
var area = calcularArea(largura, altura);
alert('A area total é: ' + area);
}
function mostrarAreaOutput() {
var largura = prompt("Digite a largura");
largura = parseFloat(largura);
var altura = prompt("Digite a altura");
altura = parseFloat(altura);
var area = calcularArea(largura, altura);
document.querySelector('#output').innerHTML = 'A area total é: ' + area;
}
function calcularArea(l, a) {
return l * a;
}
<body>
<button onclick="mostrarAreaAlert(largura, altura)">Mostrar Área em Alert</button>
<button onclick="mostrarAreaOutput(largura, altura)">Mostrar Área no Output</button>
<div id="output"></div>
</body>
Perfect Fernando, this answer was very useful too. Our friend @Asleep gave a comment above, where he answered precisely the question I had, why my code didn’t run. He reported that it was only removing width and height from inside the onclickmouse of the Uttons, and really solved. Anyway, thank you so much for the time you devoted to answering my question, because it was as useful as the other, I learned another way to accomplish with your comment. Thank you very much.
– Lucas Rodrigues