Return Part of an Array Using the slice Method

Return Part of an Array Using the slice Method
0

Tell us what’s happening:
I think i got it right, but i keep getting newArray is not defined.

Your code so far


function sliceArray(anim, beginSlice, endSlice) {
  // Add your code below this line
  
  newArray=anim.slice(beginSlice,endSlice);
  return newArray;

  // Add your code above this line
}
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
sliceArray(inputAnim, 1, 3);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method

You need to declare your variable newArray with var, let, or const.

1 Like

Here is my solution if anyone’s stuck :slight_smile:

function sliceArray(anim, beginSlice, endSlice) {
  // Add your code below this line
  var new_array = anim
  return new_array.slice(beginSlice, endSlice)
  
  // Add your code above this line
}
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
sliceArray(inputAnim, 1, 3);

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

Nice link thanks for sharing

<redacted code>

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.