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 trialJason Larkin
13,970 PointsAppending an array
I am trying to add the "firstWord" variable to the beginning of the array "firstWord". The error message comes back that task 2 is no longer passing. Can anyone help please?
var spareWords = ["The","chimney","sweep's","dog"];
var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"];
var firstWord = spareWords.shift();
var lastWord = spareWords.pop();
saying.unshift(firstWord);
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Jason,
.push()
adds to the end of the array. You want to use .unshift()
instead.
push
and pop
work on the end of the array. shift
and unshift
work on the beginning of the array.
Jason Larkin
13,970 PointsThank you Jason, but I'm having no luck with that either. Any ideas?
Jason Anello
Courses Plus Student 94,610 PointsThe following passes task 3:
saying.unshift(firstWord);
Maybe try refreshing the challenge.
Jason Larkin
13,970 PointsJason Larkin
13,970 PointsThank you Jason; refreshing the browser did it! Thanks again!