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 trialmickey Odunikan
4,983 PointsThere is an error with the code
There was an error with your code: TypeError: 'undefined' is not a function (evaluating 'document.getElementByClassName('last_name')')
var fullName= document.getElementById("full_name");
var lastName= document.getElementByClassName('last_name');
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1 id="full_name"><span class="first_name">Andrew</span> <span class="last_name">Chalkley</span></h1>
<script src="app.js"></script>
</body>
</html>
2 Answers
Kelly von Borstel
28,880 PointsI think they want you to select the element by tag name. And since it's the second span tag it would have an index of 1, like this:
var fullName = document.getElementById("full_name");
var lastName = document.getElementsByTagName("span")[1];
shezazr
8,275 PointsWhy did you choose document.getElementByClassName for your second line? this returns a collection since class can be applied to multiple elements
mickey Odunikan
4,983 Pointshow else can I select the second span element if the is no other specifier
mickey Odunikan
4,983 Pointsmickey Odunikan
4,983 Pointshaha duh thanks I completely forgot about that
mickey Odunikan
4,983 Pointsmickey Odunikan
4,983 Pointsnow it is saying that the first step is wrong.
which was the id method
Kelly von Borstel
28,880 PointsKelly von Borstel
28,880 PointsHi Mickey, I just copied and pasted my code into the challenge and it passed. You might have a typo. If you post your code again I can take a look and see if I notice any.
mickey Odunikan
4,983 Pointsmickey Odunikan
4,983 PointsYup typo got it now thanks again!!!
Kelly von Borstel
28,880 PointsKelly von Borstel
28,880 PointsJust a note about the error hints from the system: If you make an error in task two, it will often say that task one is incorrect, even if you don't change anything at all to do with task one. The error hints are not always completely accurate or helpful.