Tell us what’s happening:
Describe your issue in detail here.
Your code so far
slice() doesn’t work in IDE in browser
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/116.0.0.0 Safari/537.36
Challenge: Basic Data Structures - Copy Array Items Using slice()
The slice method is non-mutating. It returns a new “slice” of the array it was called on. Unlike splice which does mutate the array.
Yes, the names are confusing. You really only need to remember what one of them does and use deductive reasoning.
A slice is a piece of the old total. Yes, IRL we can’t really take a piece of the pie and leave the pie unchanged. But with a digital pie, we can make as many copies as we like.
Splicing is a change to the original. You can use “Gene Splicing” as a mnemonic.