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.

3rd Jul 2020, 3:14 PM
Yamkela Mazwi
Yamkela Mazwi - avatar
6 Answers
+ 8
You getting this error because your javascript part id not working may be try to fix it.
4th Jul 2020, 4:28 AM
AS Raghuvanshi
AS Raghuvanshi - avatar
+ 4
Please show your code using code playground https://www.sololearn.com/post/75089/?ref=app
3rd Jul 2020, 3:28 PM
Gordon - avatar
+ 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
3rd Jul 2020, 3:48 PM
+ 1
<p I‘d=„demo“> shall be <p id=„demo“>
3rd Jul 2020, 3:18 PM
JaScript - avatar
+ 1
really appreciate it man thanks
3rd Jul 2020, 3:52 PM
Yamkela Mazwi
Yamkela Mazwi - avatar
you’re also missing the opening { of your if and the closing } of your function.
4th Jul 2020, 5:28 PM