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

132
Visualizações
Why reply variable is giving index number of greetReply array? I want the value from that array

var submit = document.getElementById("submit");
var value = document.getElementById("value");

var greeting = ['hi', 'hello', 'Hlw', 'hello jii', 'hey', 'helo', 'hi there', 'hey']
var greetReply = ['hlw', 'kisu na', 'gaan shuni'];


submit.addEventListener('click', () => {
    const reply = Math.floor(Math.random() * greetReply.length); // random reply!

    for (let i = 0; i < greeting.length; i++) {
        if(value.value === greeting[i]){
            console.log(reply)
        }
    }
})

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

0

you have to access the value of the array by the index number, try to modify this line:

console.log(greetReply[reply])

about 4 years ago · Juan Pablo Isaza Relatório

0

reply is a random index from greetReply to get value of that index use it this way greetReply[reply]

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