Ask coding questions

← Back to all posts
ReferenceError
AstrumDeorum (52)

I'm testing out some stuff, and it's not going quite as I hoped.
The variable is declared, but it seems to not realize this I think. What's up?

ReferenceError: cookies is not defined
    at clickCookie (/:14:7)
    at HTMLImageElement.onclick (/:22:76)
Answered by ch1ck3n (1624) [earned 5 cycles]
View Answer
Comments
hotnewtop
ch1ck3n (1624)
    var cookies;
    function startCookies() {
      cookies = 0;
      document.getElementById("cookieCount").innerHTML = cookies;
    }
    function clickCookie() {
      cookies++;
      document.getElementById("cookieCount").innerHTML = cookies;
    }

put this in your script tag

AstrumDeorum (52)

@ch1ck3n It works! I guess it was just a matter of I had something too enclosed.
Thanks!