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!
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
Nurbek Ismailov
2,068 Pointsthis code is not running, please help me debug it.
<head> <script type="text/javascript"> var image_tracker='f'; function change () { var image=document.getElementById('social'); if (image_tracker==='f') { img.src='twitter.png'; image_tracker='t'; } else { img.src='facebook.png'; image_tracker='f'; } }; </head> </script> <body> <img src='facebook.png' alt="social logo" id='social' onclick="change();"> </body>
3 Answers

Nathan Ward
7,907 PointsHi,
You are setting the image to a variable called 'image' but then changing the src using the variable 'img' this could be your problem. Here is an updated version of your javascript:
var image_tracker = 'f';
function change() {
var image = document.getElementById('social');
if (image_tracker === 'f') {
image.src = 'twitter.png';
image_tracker='t';
} else {
image.src = 'facebook.png';
image_tracker = 'f';
};
}

Jennifer Nordell
Treehouse TeacherIn your html above you're closing your head tag before you close the script tag:
</head> </script>
Try this instead:
</script> </head>

Nurbek Ismailov
2,068 Pointsthank you guys, you both debugged it.
Nurbek Ismailov
2,068 PointsNurbek Ismailov
2,068 PointsNathan, thank for catching it, that was valid error, however it still not working. the images take up the the whole page and may be that is why when i click on it it is not changing from facebook to twitter and vice versa.