Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
Función que devuelve nulo

Estoy tratando de obtener el valor de un tipo de entrada de número, pero cuando intento mostrar el valor, devuelve un valor nulo (ps: lo siento, todavía soy un estudiante de secundaria) HTML:

 <label for="nummatch"><h2>Number of Match/es:</h2></label> <input type="number" onkeyup="stop(this)" id="nummatch" name="number of matches" value="1" min="1" max="5"> <br> <a href="../html/Game Page.html#vsComputer"><button onclick="number()"><h1>VS Computer</h1></button></a>

JavaScript

 function number(){ var times = document.getElementById("nummatch").value; return timesNum; } var time = number(); console.log(time)

el archivo console.log devuelve un error "Error de tipo no detectado: no se pueden leer las propiedades de nulo (leyendo 'valor')"

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Como puedo ver, está devolviendo un nombre de variable diferente dentro de la función 'número'.

Aquí hay un código JavaScript correcto con código HTML completo:

Finalmente, espero haber sido claro y útil, ¡Gracias!.

 <label for="nummatch"><h2>Number of Match/es:</h2></label> <input type="number" onkeyup="stop(this)" id="nummatch" name="number of matches" value="1" min="1" max="5"> <br> <a href="../html/Game Page.html#vsComputer"><button onclick="number()"><h1>VS Computer</h1></button></a> <script> function number() { var times = document.getElementById("nummatch").value; return times; } var time = number(); console.log(time) </script>

about 4 years ago · Juan Pablo Isaza Report

0

Algo falta. Agrega un evento onkeyup que llama a la función stop(). Agrego esta función a su código y funciona bien.

 function stop() { var time = number(); console.log(time) } function number(){ var times = document.getElementById("nummatch").value; return times; }
 <label for="nummatch"><h2>Number of Match/es:</h2></label> <input type="number" onkeyup="stop(this)" id="nummatch" name="number of matches" value="1" min="1" max="5"> <br> <a href="../html/Game Page.html#vsComputer"><button onclick="number()"><h1>VS

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!