0

I'm starting a series of simple exercices in JS and im getting stucked just at the beiginning of this.

Can someone bring me some light about what is going on? I don't see where is the mistake.

Thanks :)

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Basicos Laura</title>
  <script>
    window.onload = ejerciciosBasicos;
    function ejerciciosBasicos() {
      //1) HACER UN MÉTODO QUE RECIBA UNA CADENA Y UN CARÁCTER Y DIGA SI ESE CARÁCTER PERTENECE A LA CADENA O NO.

      function comprobarCadena() {
        var palabra = document.getElementById("introducidoPorUsuario").value
        console.log = palabra;
        return palabra;
      } //cierra comprobarCadena
    } //cierra ejercicios basicos
  </script>
</head>

<body>
  <div id="ejercicio1">
    Ejercicio 1
    <input type="text" id="introducidoPorUsuario">
    <input type="text" id="letraIntroducidaPorUsuario">
    <input type="button" value="Ok" onClick="comprobarCadena();">
    <input type="text" id="inResultado">
  </div>
</body>

</html>

1 Answer 1

2

comprobarCadena isn't a global. It only exists in the scope of ejerciciosBasicos.

Don't use an onclick attribute. Bind your event handler with addEventListener inside ejerciciosBasicos so that it is in scope.

Sign up to request clarification or add additional context in comments.

2 Comments

I've never used that (less than 1 month experience). I'm trying to undertand documentation on the mozzila developer but I cannot see how it works.
@KaiEis — Have you read the section headed "Add a simple listener"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.