Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRobbie Thomas
31,093 PointsAdding Events
I'm very confused on this one, and also with the video that goes along with this code challenge, I think Andrew Chalkey (Spelled his name wrong more than likely) was also confused while showing us how to do it. Help?
var sayButton = document.getElementById("say");
var greeting = function() {
alert("Hello World!");
}
greeting.onClick = say;
<!DOCTYPE html>
<html>
<head></head>
<body>
<button id="say">Say "Hello World!"</button>
<script src="app.js"></script>
</body>
</html>
3 Answers
Kieran Black
9,139 PointsHi Robert,
Line 5 - so the full challenge would be:
var sayButton = document.getElementById("say");
var greeting = function() {
alert("Hello World!");
}
sayButton.onclick = greeting;
Kieran Black
9,139 PointsHi Robert,
You were close.
Your button is assigned to the variable sayButton and our function is within the variable greeting, so when we click the sayButton we want to run greeting().
We can do this by:
sayButton.onclick = greeting;
Note the lower case of onclick as opposed to onClick. In your current attempt you were trying to call an undefined item say on the function greeting (instead of the button sayButton).
Good luck, and happy coding.
KB
Robbie Thomas
31,093 PointsI tried that, still giving me the bummer message. This needs to be on line 4, correct?