Copy Array Items Using slice() help

Am i doing something wrong here

Your code so far


function forecast(arr) {
  // change code below this line
  

  return arr.slice(2,3);
}

// do not change code below this line
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/copy-array-items-using-slice

Check the browser console to see what your forecast function returns. Then tweak the values you pass to slice and compare the results

If anyone still has troubles:
-create a new variable in which to store the new array
-return the new variable.

let modifiedArray = arr.slice(2, 4);
return modifiedArray;

I stopped at 4 because "the second is the index at which to stop extraction (extraction will occur up to, but not including the element at this index)."

1 Like