The result is always the same, as if the conditions were equal

Asked

Viewed 24 times

-1

    <div>
        <p>qual seu  pais de origem?</p>
        <input type="text" name="pergunta" id="pergunta">
        <input type="button" value="confirmar nacionalidade" onclick="confirmar()">
        <div id="nacionalidade"> :</div>
    </div>
    <script>
        function  confirmar(){
            var pergunta = window.document.querySelector('input#pergunta');
            var nacionalidade = window.document.querySelector('div#nacionalidade');

            if (pergunta == 'Brasil'){
                nacionalidade.innerHTML = ('ola,brasileiro')
            }else{
                nacionalidade.innerHTML =  ('Olae strangeiro')
            }
        }    
    </script>
</body>

1 answer

1


If you give a console.log in the question you will see that it returns the whole Input element, and according to your if, it falls into the "Strange Olae'". Use pergunta.value in the if.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.