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 trialBob Sutherton
20,160 PointsArray Methods shift/unshift CODE CHALLENGE (not sure what i'm doing wrong!)
So here is the link to the code challenge question.
https://teamtreehouse.com/library/websites/javascript-foundations/arrays/methods-part-1-elements
Here is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<title> JavaScript Foundations: Arrays</title>
<style>
html {
background: #FAFAFA;
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>JavaScript Foundations</h1>
<h2>Arrays: Methods Part 1</h2>
<script>
var spareWords = ["The","chimney","sweep's","dog"];
var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"];
var firstWord = spareWords;
var lastWord = spareWords;
spareWords.unshift(firstWord);
spareWords.shift(firstWord);
saying;
saying;
</script>
</body>
</html>
3 Answers
Bob Sutherton
20,160 PointsIs it possible that there is a bug on this code challenge? It is giving me an error:
"Bummer! You're missing the shift method."
spareWords.shift(firstWord);
ilker senturk
17,583 Pointsvar firstWord = spareWords; var lastWord = spareWords;
you need to get the first value of the array by adding shift() method
spareWords.shift();
Bob Sutherton
20,160 PointsThanks for your reply. When I try that, it doesn't work.
Sreng Hong
15,083 PointsYou can take a look Array Object Methods here
Sreng Hong
15,083 PointsSreng Hong
15,083 PointsHi, James!!! There isn't a bug on this code challenge. You don't need to type firstWord in the bracket. <br /> The right answer is like this: <br />
var firstWord = spareWords.shift();
Sreng Hong
15,083 PointsSreng Hong
15,083 Pointsmethod shift() means removes the first element of an array, and returns that element
Bob Sutherton
20,160 PointsBob Sutherton
20,160 PointsThanks for your help, Sreng!
Sreng Hong
15,083 PointsSreng Hong
15,083 PointsYour welcome