Tell us what’s happening:
What is wrong in this code?
Your code so far
function htmlColorNames(arr) {
// change code below this line
let newColor = ['DarkSalmon', 'BlanchedAlmond'];
arr.splice(0, 2, newColor);
// change code above this line
return arr;
}
// do not change code below this line
console.log(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'PaleTurqoise', 'FireBrick']));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.
This Stack Overflow post helped me with adding multiple array values.
The tl;dr version of that post is…
The first parameter to splice is the index to start with, the second is the number of elements to remove, the remainder are elements to insert. So if you insert the same number as were removed, you end up replacing them.
So a solution to this challenge is…
function htmlColorNames(arr) {
// change code below this line
arr.splice(0, 2, 'DarkSalmon', 'BlanchedAlmond');
// change code above this line
return arr;
}
If I’m not mistaken, we have exactly the same code:
function htmlColorNames(arr) {
// change code below this line
arr.splice(0, 2, ‘Darksalmon’, ‘BlanchedAlmond’);
// change code above this line
return arr;
}
Now it just so happens that mine doesn’t give me a check for the criteria:
``htmlColorNames should return [“DarkSalmon”, “BlanchedAlmond”, “LavenderBlush”, “PaleTurqoise”, “FireBrick”]
Is this really right, if so, is there a bug, or else; how to solve challenge?