简体   繁体   中英

“Inspect” function (Ctrl + Shift + I) doesn't work

The "if (numero.value.length == 0)" works, but when I add a number the program doesn't work, the "Inspect" function (Ctrl + Shift + I) doesn't work and the page does not refresh.

 function tabuada() { var numero = document.getElementById('txtnum') var tabuada = document.getElementById("selectTab") if (numero.value.length == 0) { window.alert("Você precisa digitar um número para que a tabuada seja gerada.") } else { var num = Number(numero.value) tabuada.innerHTML = "" for (c = 0; c = 10; c++) { var item = document.createElement('option') item.text = `${num} * ${c} = ${c * num}` tabuada.appendChild(item) } } }
 <section> <div> <p> Escolha um número: <input type="number" name="num" id="txtnum"> <input type="button" value="Gerar Tabuada" onclick="tabuada()"> </p> </div> <div> <select name="tabuada" id="selectTab" size="10"></select> </div> </section>

You had to look more on your code:

  • Every opnening tag needs a closing one. /BODY and /HTML was missing.
  • Every line in Javascript needs a ; at the end.
  • The condition of your for-loop was wrong. You made an allocation c = 10 (which is allways true, so you have an infinite loop). If you want to compare something on equal use === or == . But you had to compare for c < 10 . The loop will as long iterate as your condition is true so smaller than is the choice.
  • Your function needs a closing } .

 function tabuada() { var numero = document.getElementById('txtnum'); var tabuada = document.getElementById("selectTab"); if (numero.value.length == 0) { window.alert("Você precisa digitar um número para que a tabuada seja gerada."); } else { var num = Number(numero.value); tabuada.innerHTML = ""; for (c = 0; c < 10; c++) { var item = document.createElement('option'); item.text = `${num} * ${c} = ${c * num}`; tabuada.appendChild(item); } } }
 <!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tabuada</title> <link rel="stylesheet" href="_estiloEx16.css"> </head> <body> <header> <h1>Tabuada</h1> </header> <section> <div> <p> Escolha um número: <input type="number" name="num" id="txtnum"> <input type="button" value="Gerar Tabuada" onclick="tabuada()"> </p> </div> <div> <select name="tabuada" id="selectTab" size="10"></select> </div> </section> <footer> <p>&copy; Curso em vídeo</p> </footer> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM