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

202
Visualizações
Creating a function to print an answer w/ Jprompt

I've created a word matching game. In this game the program generates a set of words, "keys" and a set of "descriptions". The goal of this program is create a set of "keys" that can be matched to a set of "descriptions". For example, element with id el1 should be paired with element with id dl1.

I've created the html for the user interface and the javascript for rendering the html. There is a button that shows the answer for the game. When the button is clicked show_answer() is called.

    // initialize the answer.
    var answer = '';
   function show_answer() {
      // retrieve the keys and descriptions. Then load them into their respective arrays.
      const e_inputs = document.querySelectorAll("[id^='el']");
      const d_inputs = document.querySelectorAll("[id^='dl']");
      let elArray = [];
      let dlArray = [];
      const title = document.getElementById('title_input').value;
      for (let i = numberOfInputs; i < elArray.length; i++) {
          text += `${elArray[i]}:${dlArray[i]}\n`;
          answer += elArray[i];
          answer += ':';
          answer += dlArray[i];
          answer += '\n';
      }
      jAlert(answer, 'Correct Match');
    }

The issue is that the answer is coming back blank. enter image description here

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

0

function show_answer() {
      // retrieve the keys and descriptions. Then load them into their respective arrays.
      const e_inputs = document.querySelectorAll("[id^='el']");
      const d_inputs = document.querySelectorAll("[id^='dl']");
      let elArray = [];
      let dlArray = [];
      const title = document.getElementById('title_input').value;
      e_inputs.forEach( i => { if(i.value) elArray.push(i.value) });
      d_inputs.forEach( i => { if(i.value) dlArray.push(i.value) });

      //reset the answer once the generate_html() is called.
      answer = '';
      for (let i = 0; i < elArray.length; i++) {
          answer += `${elArray[i]}`;
          answer += ':';
          answer += `${dlArray[i]}`;
          answer += '\n';
      }
      jAlert(answer, 'Correct Match');
    }
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