简体   繁体   中英

Uncaught TypeError: Cannot set property 'innerHTML' of null in line 34

I've already searched for my problem, but the solutions were not able to help me.

Here's the code:

<!DOCTYPE html>
<html>



<head>
  <meta charset="utf-8">
  <title>Der Einmaleins - Trainer</title>  
  <link href = "style.css" type = "text/css" rel = "stylesheet">

</head>
<body>
  <h1>Der Einmaleins - Trainer</h1> 
  <button type="button" onclick = "start();">Start</button> 
  <button type = "button" onclick = "fertig();">Fertig!</button>
  <input id = "erginput" type = "number" >
  <br>
  <label id = "rn1"></label>  
  <label id = "multiplication"><label>
  <label id = "rn2"></label>  

<script>

function start() 

{   
//var anzahl = 0
//while (anzahl < 20){

var randomnumber1 = getrn();
var randomnumber2 = getrn();
document.getElementById("rn1").innerHTML = randomnumber1;
document.getElementById("multiplication").innerHTML = "x";
document.getElementById("rn2").innerHTML = randomnumber2;
//}
}

function getrn(){
var min = 3;
var max = 10;
var randomnumber = Math.floor(Math.random() * (max - min)) + min;
return randomnumber;
}</script>
</body>

I thought that the null is because randomnumber2 oder rn2 is not defined since I saw that mistake in other codes, but here they're both defined, aren't they?

Thanks in advance!

Ji W

You had invalid markup! </label> was not closed..

 function start() { var randomnumber1 = getrn(); var randomnumber2 = getrn(); document.getElementById("rn1").innerHTML = randomnumber1; document.getElementById("multiplication").innerHTML = "x"; document.getElementById("rn2").innerHTML = randomnumber2; } function getrn() { var min = 3; var max = 10; var randomnumber = Math.floor(Math.random() * (max - min)) + min; return randomnumber; } 
 <h1>Der Einmaleins - Trainer</h1> <button type="button" onclick="start();">Start</button> <button type="button" onclick="fertig();">Fertig!</button> <input id="erginput" type="number"> <br> <label id="rn1"></label> <label id="multiplication"></label> <label id="rn2"></label> 

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