Why isn’t my code working? (Javascript) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

18th Feb 2020, 3:35 PM
tori the crafter 💛
tori the crafter 💛 - avatar
5 Answers
+ 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.
18th Feb 2020, 4:11 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 2
thanks sm Mirielle👽! one question for you, what’s the difference between a local variable and a global variable?
18th Feb 2020, 6:11 PM
tori the crafter 💛
tori the crafter 💛 - avatar
+ 1
Utkarsh Sharma i changed it though and the code still isn’t working
18th Feb 2020, 3:50 PM
tori the crafter 💛
tori the crafter 💛 - avatar
0
You forgot the dot befor innerHTML in line 9 It should be : document.getElementById("fortune").innerHTML="You will have an awesome life"
18th Feb 2020, 3:45 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
0
Utkarsh Sharma thanks i wouldnt have ever spotted that mistake lol
18th Feb 2020, 3:50 PM
tori the crafter 💛
tori the crafter 💛 - avatar