0
Uncaught reference error
Hi I’m working with VS Studio and I’ve been trying to execute some code however I keep getting uncaught reference error saying “greeting is undefined”. I’m using chrome and the error appears on the console log. Here is the code I’m trying to execute. <button type=“button” onclick=“testFunc()”> <p I’d=“demo”></p> Function testFunc() { var hour = new Date().getHours(); var greeting; If (hour < 18) greeting = “Good day”; } else { greeting = “Good evening “ } document.getElementbyId(“demo”).innerHTML = greeting; I’ve tried putting parentheses after the var greeting () but still doesn’t work. How can I solve this.
6 ответов
+ 8
You getting this error because your javascript part id not working may be try to fix it.
+ 4
Please show your code using code playground
https://www.sololearn.com/post/75089/?ref=app
+ 2
The <button> tag didn't have its counter </button> pair.
'id' attribute of the <p> tag is messed up by autocorrect feature.
You used slanted double quotes almost everywhere. Change them to standard double quotes.
Javascript is a case sensitive language, so please mind letter cases, they do matter.
Function -> function
getElementbyId -> getElementById
+ 1
<p I‘d=„demo“> shall be <p id=„demo“>
+ 1
really appreciate it man thanks
0
you’re also missing the opening { of your if and the closing } of your function.