0
How to stop getting an error for not having a value?
I want my code here to take the input a user puts for the name input and save it for when the user activates the Hello if statement for my Virtual Assistant. Right now the console will throw me an error saying it can't take null as a value. What's going on? If there's any other problems in my code besides that, please point them out. Thank you for your help. https://code.sololearn.com/WTxla4gvmCVM/#js
6 Réponses
+ 4
Try to understand the error. It's saying, "can't read property value of null on line 13" means it can't find element with id "userName" and thus returns a null and hence the error.
And it's because, the JS part gets loaded before the HTML part and so it can't find the required element.
All you need to do is to wrap your entire JS code inside a function which will be called after the HTML window gets loaded.
You can do:
window.onload= function(){
//Your entire JS code goes here
}
+ 2
Jack sorry, didn't get you. What do you mean?
BTW, your above code is missing a '}' at line 24.
+ 2
Jack no, It should not if you could do it right. Kindly share the link of that broken code.
0
Shashi Ranjan Whole code gets broken
0
you said to put all of my code inside of a function. that broke my code Shashi Ranjan