Tell us what’s happening:
What I’m doing wrong here?
I’ve tried a lot of schemes for this exercise but it’s always missing the last objective to return the values, I don’t know what’s going on…
Your code so far
function nonMutatingSplice(cities) {
// Add your code below this line
var x = cities.slice(3,4);
return x;
// Add your code above this line
}
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36.
The method slice(a, b) takes two parameters:
a) beginning index (inclusive).
b) ending index (exclusive).
When you code calls slice() it is returning null since the parameters are in the wrong order with slice(3, 1), and returning index 3 and everything after with slice(3).
That’s true, but the instructions also explain what arguments go into slice. Recall that the slice method takes two arguments for the indices to begin and end the slice (the end is non-inclusive), and returns those items in a new array.
Next time, though I’ll be more helpful. It’s clear i was not this time.