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

212
Visualizações
Why there are no pop up questions that I wroted? Just go to the alert("Total correct answer: "+ score ); directly

Can't display the pop-up questions I wrote, but go to the alert(total correct answer) directly. I wrote it by following the tutorial video. Can anyone help me? Thank you!!!

var questions = [
    {
        prompt:"What is the color of banana?\n(a)red\n(b)green\n(c)yellow", // \n = 換行
        answer:"c"
    },
    {
        prompt:"What is the color of strawberry?\n(a)red\n(b)green\n(c)yellow",
        answer:"a"   
    },
    {
        prompt:"how many centimeters is equal to One meter?\n(a)1\n(b)10\n(c)100",
        answer:"c"   
    }
]

var score = 0;
for(var i=0; i<questions.lengths; i++){
    var input=prompt(questions[i].prompt);
    if(input==questions[i].answer){
        score++;
        alert("Answer Correct!");
    }
    else{
        alert("Answer Wrong!");
    }
}

alert("Total correct answer: "+ score );
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

questions.lengths should be questions.length. You can read more about how to get the length of an array in Javascript here

var questions = [
    {
        prompt:"What is the color of banana?\n(a)red\n(b)green\n(c)yellow", // \n = 換行
        answer:"c"
    },
    {
        prompt:"What is the color of strawberry?\n(a)red\n(b)green\n(c)yellow",
        answer:"a"   
    },
    {
        prompt:"how many centimeters is equal to One meter?\n(a)1\n(b)10\n(c)100",
        answer:"c"   
    }
]

var score = 0;
for(var i=0; i<questions.length; i++){ // This is the line which was incorrect
    var input=prompt(questions[i].prompt);
    if(input==questions[i].answer){
        score++;
        alert("Answer Correct!");
    }
    else{
        alert("Answer Wrong!");
    }
}

alert("Total correct answer: "+ score );

about 4 years ago · Juan Pablo Isaza Relatório

0

You have a typo:

for(var i=0; i<questions.length; i++){

length - not lengths

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