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 trialSteven Quinn
12,519 PointsProblem with task
Is it just me or is there a conflict with the code in the third part of this task. My code passes for the first and second parts of the task, but when I try to complete the third part it says that the first part is no longer ok. Maybe because the variable we are asked to use is the same for both part one and part three?
<!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.shift();
var lastWord = spareWords.pop();
var firstWord = saying.unshift();
saying;
</script>
</body>
</html>
1 Answer
Stefan Osorio
16,419 PointsShould someone else encounter this Problem, a possible solution would be:
var firstWord = spareWords.shift();
var lastWord = spareWords.pop();
saying.unshift(firstWord);
unshift() adds the element(s) which are passed to it (in the parentheses) to the beginning of the array it was called on, and returns the new length of said arraid.
In Stevens Code ("var firstWord = saying.unshift()") unshift() is called on "saying" and returns it's length, which is then assigned to "firstWord". This is why Task 1 isn't passing anymore.
Steven Quinn
12,519 PointsSteven Quinn
12,519 PointsNever mind! Found out what I was doing wrong.