The ideal would be to learn in a structured way, to understand the reason for each thing.
Can not have a semicolon after the condition of if
or else
. The ;
encloses a declaration, and the whole block of if
is a unique statement.
In addition, when you put a condition in else
it should be followed by if
.
When you compare a variable with a text, the text must be enclosed in quotation marks, otherwise it is interpreted as a variable.
There are a number of other things that can be improved in this code.
var n1 = parseInt(prompt("Digite um número"));
var n2 = parseInt(prompt("Digite outro número"));
var A = n1 + n2;
var M = n1 * n2;
var D = n1 / n2;
var Sub = n1 - n2;
var menu = prompt("Escolha uma opção:\nA - Adição\nM - Multiplicação\nD - Divisão \nS - Subtração")
if (menu == "A") {
alert(A);
} else if (menu == "M") {
alert(M);
}