+ 1
Why isn’t my code working? (Javascript)
I want the fortune to appear after 10 clicks but I keep getting a syntax error. Can someone tell me what I did wrong? https://code.sololearn.com/W4ZuEAA671kx/?ref=app
7 Respuestas
+ 3
tori the crafter 💛 Try this --
var clicks = 0
function increase() {
clicks++;
document.getElementById("cookie").innerHTML=clicks
if (clicks > 10) {
document.getElementById("fortune").innerHTML="You will have an awesome life"
}
}
The problem in your code was that the condition was not included in the loop. Since it was not in the loop it was not executed. You code in HTML calls increase() but the condition was not in the increase() function, and also... Change while to if.
+ 2
thanks sm Mirielle👽! one question for you, what’s the difference between a local variable and a global variable?
+ 1
Utkarsh Sharma i changed it though and the code still isn’t working
0
You forgot the dot befor innerHTML in line 9
It should be :
document.getElementById("fortune").innerHTML="You will have an awesome life"
0
Utkarsh Sharma thanks i wouldnt have ever spotted that mistake lol