Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
Can I have multiple answers for a question in js?

I'm making a trivia game for my website, but I want to have multiple answers for questions, just to make it a bit easier for people to answer. Everything I tried was wrong, so what can I do? Javascript:

function quiz() {
var score=0;  
var totalQuestions=3;
alert("Welcome to my trivia game!");
alert("Make sure you answer all the questions.");

var q1=prompt("What war occured in 1812?");        
if(q1=="the 60 year war"    ) {
    score=score+1;  
    alert("Correct!"); 

} else {
    alert("Incorrect! The correct answer is the 60 year war!");  

}

var q2= prompt("When did the revolutionary war start?") ;       
if(q2=="1775"    ) {
     score=score+1; 
    alert("Correct!");  

} else {
    alert("Incorrect! The right answer is 1775!");  

}

var q3=prompt("If you're trying to fail and you succeed, did you fail or succeed?");  
if(q3=="you succeeded"  ) {
     score=score+1; 
    alert("Correct!");  

} else {
     alert("Incorrect! You succeeded!"); 

}

alert("You got " + score + " questions out of " + totalQuestions + " correct." );  

}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use OR "||" condition

if(q1=="the 60 year war" || "SECOND ANSWER HERE ") {
    score=score+1;  
    alert("Correct!"); 

} else {
    alert("Incorrect! The correct answer is the 60 year war!");  

}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda