Puffycheeses Puffycheeses - 2 years ago 82
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


Play the game:

Related JavaScript:

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

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

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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download