Create input showing if it is right or wrong

1

My current project consists of a section in which through a javascript (preferably), you have to write a word in an input. Then, you could know if it is the correct word or it is not, then it would be incorrect.

I have been thinking about all the possibilities, and the only thing that I have arrived at the moment is this code that would generate what I am looking for, but at a prompt (something similar to a popup).

 function checkAnswer(){
    prompt('Cuál es la capital de francia?')
    if('paris'){
        alert('Correcto')
    }
    else{
        alert('Incorrecto. La respuesta correcta sería París')
    }

}
<p>Cuál es la capital de Francia </p>

<button onclick="checkAnswer()">Ir a la pregunta</button>

However, besides that it does not work for me, it's not what I need, since I need it to be generated on the php page itself.

Would you know by chance which function I can use? or if you have a specific name what I'm looking for?

Many thanks and best regards to all

    
asked by CRS1234 24.09.2017 в 21:36
source

1 answer

1

I have not understood very well what you need, but I have done this example to see if it helps you.

I have edited the condition part.

function validarRespuesta() {
  var input = document.querySelector('input[name="respuesta"]');
  var resultado = document.getElementById('resultado');
  var value =  input.value;
  resultado.innerText = value == 'paris' || value == 'parís' ? 'Correcto' : 'Incorrecto';
}
<p>¿Cuál el la capital de Francia?</p>
<input placeholder="Introduce la respuesta" name="respuesta"/>
<button onClick="validarRespuesta()">Validar respuesta</button>
<p id="resultado"></p>
    
answered by 24.09.2017 / 22:12
source