Puffycheeses Puffycheeses - 7 months ago 11
HTML Question

Function can't find variable

I was messing around with my game's CSS, and now I get a variable error for every button I click that calls a function, saying it can't find the variable.

I deleted the CSS and everything has changed, but the game is still broken.
I don't know whats wrong, so I have provided a link to download the code.

The error:

reference error: can't find variable: duckClick


Download:
https://dl.dropboxusercontent.com/content_link_zip/byJEtJ2Bj1FkHjOk9wlBrCEglCgWntWGsZUrHBUWDKBsoBJ3bsNVEnQPmoMgJqus

Play the game:
https://dl.dropboxusercontent.com/u/104187515/TIGWNN/index.html



Related JavaScript:

var ducks = 0;
function duckClick(number){
ducks = ducks + number;
document.getElementById("ducks").innerHTML = ducks;


This calls
duckClick
but I'm getting a error saying it can't find it.

<button onclick="duckClick(1)">Find Duck</button>

Answer

Ah... a little does go a long way, especially in programming.

You forgot the curly closing duckClick, leaving it undefined.

function duckClick(number) {
    ducks = ducks + number;
    document.getElementById("ducks").innerHTML = ducks;
} //This curly brace