Never use double quotes ( "
) inside double quotation marks, or single quotation marks ( '
) within single quotation marks, or if you need to do so, you'll have to use a technique to escape the string using something from the type \string para escapar\
, otherwise you will be closing the attribute, if you open the browser console you can see how it reads the code snippet:
Wheninfactitwassupposedtohavebeenreadlikethis:
Youalsoconfusedtheresponsevariablewiththeresultvariablethatdidnotevenexist.
Thecorrectcodecouldbelikethis
function calculaRetangulo(b, h) {
var area = (b * h);
var perimetro = (b + h) * 2;
return [area, perimetro];
};
<button type="button" onclick="var resposta = calculaRetangulo(5,10); alert('AREA: '+resposta[0]); alert('Perimetro: '+resposta[1])">EXECUTAR</button>