Tell us what’s happening:
i am doing it right but it is not being accepted by as a correct answers, i have tried many times plz help Your code so far
function forecast(arr) {
// Only change code below this line
arr.slice(2,4);
return arr;
}
// Only change code above this line
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.
slice() , rather than modifying an array, copies, or extracts , a given number of elements to a new array, leaving the array it is called upon untouched.
I’m sorry if I confused you a bit, but @ILM has explained it well right there. .slice(); doesn’t work like .splice();.The .splice(); modifies the array and then returns the modified array, while .slice(); grabs the array and slice it, but the difference is that it creates a NEW array. If you don’t assign it like this:
let arr = [1, 2, 4, 6];
let arr1 = arr.slice(2,6);
It will just slice, create a new array and ignore it.