Return Part of an Array Using the slice Method

Return Part of an Array Using the slice Method
0

#1

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


#2

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


#3

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);

#4

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.


#5

Nice link thanks for sharing