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 trial
Candice Coghill
30 Pointsundefined errors for the two functions
I am trying to change the picture depending on which button is pushed. On the click the paragraph should change along with the background color. It is showing as my functions being undefined even though they are placed in the header.
<!DOCTYPE html> <html> <head> <title>CIT Candice Coghill Javascript"</title>
<script>
function pictureOne() {
document.getElementById("myImage").src = "thissummer.jpg";
document.getElementById("first").style.backgroundColor = DarkOrchid;
document.getElementById("first").innerHTML = "This Summer.The bestie and I in the front seat.
My husband and her youngest in the back. We were headed to Meade County!";
} function pictureTwo() { document.getElementById("myImage").src = "lastsummer.jpg"; document.getElementById("first").style.backgroundColor = Aqua; document.getElementById("first").innerHTML = "Last Summer.The bestie and I in the front seat. My husband and her oldest daughter in the back. We were on our way to shoot a family house in Meade county that had been abandoned!"; } </script>
</head> <body style= "background-color:CadetBlue;"> <style> h1 { margin: 10px; height: 30px; width: 600px; border:10px dotted black; padding: 10px; text-align:center; font-family="Comic Sans MS", cursive, sans-serif; size="25"; color:lightpink; background-color:Chartreuse; } p { margin: 10px; height: 30px; width: 600px; border:10px double yellow; padding: 10px; font-family="Times New Roman", Times, serif; size="10"; color:Crimson; background-Color:Cyan;
</style>
<h1>CIT 150- Candice Coghill- Javascript</h1>
<p id="first">Summer Fun!</p>
<button onclick="pictureOne()";>Last Summer</button>
<img id="myImage" src="summer.jpg" style="width:100px; border: 10px solid green">
<button onclick="pictureTwo()";>Last Summer</button>
</body> </html>
1 Answer
KRIS NIKOLAISEN
54,974 PointsYou had two things going on:
1) For some reason the space before "My husband and her youngest..." in function pictureOne() is causing an issue. All I did to fix was delete the space
2) Your background colors 'DarkOrchid' and 'Aqua' need to be enclosed in quotes.
Here is a snapshot of the updated page.