+ 2
Uncaught TypeError : cannot set properties of null (setting 'innerHTML')
This code just work fine in Browser but it's showing error running on SoloLearn while clicking the Guess button Uncaught TypeError : cannot set properties of null (setting 'innerHTML') https://code.sololearn.com/W0Dsws4FND40/?ref=app
7 Antworten
+ 3
This script uses a call (document.querySelector(...)) to the DOM of an html-document that has not yet been loaded.
Use onload method:
onload = ()=>{code}
+ 1
Subscribe to me and I will explain everything in detail to you in a personal 😉
+ 1
Niirmaal Twaatii
When you call function using event function then get input value inside the function don't get when code load otherwise you will get null and you cannot set value to null object.
So write this lines inside update function
var res = document.querySelector("#result");
var prev = document.querySelector("#prev");
if you want to use res and prev in another function then make them global variables then assign value
Also you should get random value inside function because it should change on every click. If you write once outside the function then random value will be always 1 so write this line inside function:
var ran = Math.floor(Math.random()*100 + 1);
https://code.sololearn.com/WimrzhG5ohE8/?ref=app
+ 1
A͢J, it's much easier than you think 😉
And "var ran = Math.floor(Math.random()*100 + 1);" you can not write inside the function as you suggest, as this will deprive the player of the next attempt that is counted.
+ 1
A͢J thanks for your help 😃 & my program is to guess the number in 10 tires so no need to generate random number on every click 😉
0
Solo can you specify which block of code to put on onload method because its getting reference error if if i put the whole code inside it 😅
0
Solo okay