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 trial
Matt Trask
10,027 PointsMethods Part 3 Question 2/3 not passing
Im trying to slice out "quick" "brown" "fox" from my array, heres my code:
var first = ["The", "quick", "brown", "fox", "jumps"]
var second = ["over", "the", "lazy"];
var saying = first.concat(second, "dog");
var shortSaying = saying.slice(1, 2, 3);
From what I can see, it looks like, but it doesnt pass, only saying Ive only isolated "quick". Any help?
1 Answer
Ben Rubin
Courses Plus Student 14,658 PointsThe slice method takes two parameters, not three. The first parameter is the starting index of the sequence that you want. The second parameter is ending index of the sequence that you want. Keep in mind that the first element in that sequence will be part of your results, but the last element in that sequence will not be part of your results. For instance, saying.slice(3, 5) would give you the words "fox" and "jumps".
The reason it's saying that you've only isolated "quick" is because your slice starts at element 1 and ends at element 2 (but doesn't include element 2), which results in just the word "quick". Since slice doesn't take a third parameter, the browser must be ignoring the 3.