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 trialKORAXE IUHMAGEON
Courses Plus Student 8,486 PointsI have no idea what I'm doing
I'm totally lost here.
var sayButton = document.getElementById("say");
var greeting = function() {
alert("Hello World!");
}
function initElement() {
p.onclick = sayButton;
}
<!DOCTYPE html>
<html>
<head></head>
<body>
<button id="say">Say "Hello World!"</button>
<script src="app.js"></script>
</body>
</html>
2 Answers
Simon Coates
28,694 Pointstry
var sayButton = document.getElementById("say");
var greeting = function() {
alert("Hello World!");
}
sayButton.onclick = greeting;
Events are attached on elements. The saybutton gets an element. The greeting creates a variable of function type. THe final line says, for this element, on a click event, do the functionality defined in greeting.
KORAXE IUHMAGEON
Courses Plus Student 8,486 PointsI magically figured it out but thanks. That is different than what I did. I believe I typed
var geeting =document.getElementById("Say");
Simon Coates
28,694 PointsSimon Coates
28,694 Pointsthe problem is that you haven't defined a variable called p. and nothing is calling initElement. And you're assigning an element as if it were the callback.