How to use function declaration with jsfiddle

Viewed 4359

I have some html/javascript that works in my .cshtml file.
When I try to move it in to jsfiddle to experiment with, it does not work.
Not sure if if it's my lack of javascript experience, jsfiddle experience, probably both....

html:

<div>
<button name="startBtn" id="startBtn" onclick="startTimer">Start</button>
</div>  

(I have also tried "startTimer()" for the onclick attribute; same result.)

javascript:

function startTimer() { alert("startTimer"); }

When I click the button, I see this in the Console:

Uncaught ReferenceError: startTimer is not defined

What am I overlooking?
(jsfiddle: http://bit.ly/1buQx9t)

6 Answers

The answers above are all right; I just wanted to clarify what/where to change with this picture to solve the issue:

Here is the jsfiddle demo

<button onclick="doThat()">
Click
</button>

function doThat() {
    console.log("click happened");
}

enter image description here

Related