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

163
Visualizações
My input-function in javascript always return false, even when a user inputs the correct value

I want to know why my function always returns false, and how I can fix it. At first I thought it had something to do with my syntax at check = ("stairway to heaven"===value || "Stairway to heaven"===value);. But no matter how I put it, it's always false.

I tried reading into this, but as far as I could understand, it doesn't help me.

I've created this in JavaScript to do different things depending on if the result of check is true or false.

else if (textNodes[15].id === 16 && nextTextNodeId === 16)  {
        showSongContainer();
        if(check) {
            showTextNode(17);
        }
        if (!check) {
            textElement.innerText = 'That’s superwrong! Maybe if you would use that small brain of yours you’d figure it out!';
            showTextNode(11);
        }

The above code runs this function first, to determine if a text input returns true (stairway to heaven) or false (anything other than stairway to heaven):

function showSongContainer() {
    songContainer.style.display = 'unset';
    const songInput = document.getElementById('songInput');
    const songButton = document.getElementById('songButton');

    songButton.addEventListener('click', (e) => {
        e.preventDefault();
        let value = songInput.value;
       
     check = ("stairway to heaven"===value || "Stairway to heaven"===value);
    });
} 

However, when the first else ifstarts (in the first codeblock), it always goes to the if(!check), before the text input has even been entered. Why is this? And how do I make it so that it returns the first if (in the first code block) if the text input is correct, and the other if, if incorrect?

I also have let check = ''; in a global scope at the beginning of my code, if that has anything to do with it.

about 4 years ago · Juan Pablo Isaza
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