I'm a beginner in JS. The script below will calculate the points of two teams, which will be informed through the prompt (yes, it's annoying, but it's for testing).
I created (or tried) a function to always do the accounts, regardless of the number of times.
What I want is that, as there are two teams, store the sum of the points of each team and at the end make the comparison, making it state who is better in the championship.
var meuTime = prompt("Digite o nome do time: ");
var vitoriasMeuTime = prompt("Quantas vitórias seu time tem? ");
var empatesMeuTime = prompt("Quantos empates seu time tem? ");
var timeAdversario = prompt("Digite o nome do time adversário: ");
var vitoriasAdversario = prompt("Quantas vitórias eles tem? ");
var empatesAdversario = prompt("Quantos empates eles tem? ");
function calculaPontos (time,vitorias,empates){
var pontos = (vitorias * 3) + parseInt(empates)
document.write(time + " tem " + pontos + " pontos! ");
}
calculaPontos (meuTime, vitoriasMeuTime, vitoriasMeuTime);
calculaPontos (timeAdversario, vitoriasAdversario, empatesAdversario);
if(pontosMeuTime > pontosAdversario){
document.write("Estamos melhor que eles!");
} else if (pontosMeuTime == pontosAdversario){
document.write("Empatados com eles!");
} else {
document.write("Estamos atrás, vamo logo crl!");
}