JS Console Throwing TypeError on a Line That Doesn't Even Exist
Hi team, As soon as I start the app I get a TypeError from the JavaScript console on a line of code that doesn't exist at all: TypeError: document.getElementById(...) is null Line: 38 There is no line 38 in my code. The argument that I pass to getElementById is updater, which is the ID of the <p> tags at the bottom of the HTML code. Troubleshooting this error, I put in a value between the <p> tags just in case, but still I get the error, so I don't understand what it means when it says that it's null. Here's the app: https://code.sololearn.com/WL49Wo3JsMDG/#js HTML: <!DOCTYPE html> <html> <head> <title>Sword Roulette</title> </head> <body> <h2>Number of unbelievers in the execution circle:</h2><br /> <input type = "text" id = "killBox"/> <button type ="button" onclick = createUnbelievers()>Create some unbelievers</button> <button type ="button" onclick = getListOfUnbelievers()>List the unbelievers</button> <button type ="button" onclick = killUnbelievers()>Kill the unbelievers!</button> <button type ="button" onclick = resurrect()>Resurrect!</button> <p id = "updater">Test</p> </body> </html> JavaScript: var unbelieverList = []; var numberOfUnbelievers = document.getElementById("killBox").value; var statusMessage = document.getElementById("updater"); statusMessage.innerHTML = ""; function createUnbelievers() { // create infidels statusMessage.innerHTML += "Creating unbelievers..."; for (unb = 0; unb < numberOfUnbelievers; unb++) { unbelieverList.push("Unbeliever" + Math.random(2)); statusMessage.innerHTML += "Unbelievers have been created."; } } function getListOfUnbelievers() { statusMessage.innerHTML += "\n\nList of Known Unbelievers\n"; for (unb = 0; unb < unbelieverList.length; unb++) { statusMessage.innerHTML += unbelieverList[unb]; + "\n"; } } function killUnbelievers() { statusMessage.innerHTML = "\n\nKilling the unbeliever