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 Respostas
+ 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.