Removing element using splice

Tell us what’s happening:
So,my code is not meeting the requirement below:

arr should only contain elements that sum to 10

Can someone please guide me on getting through this challenge?

Your code so far


const arr = [2, 4, 5, 1, 7, 5, 2, 1];
// only change code below this line
function sumOfTen(arr) {
// change code below this line
   arr.splice(1, 5);
//console.log(arr);
// change code above this line

}
// only change code above this line
console.log(arr);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0.

Challenge: Remove Items Using splice()

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice

First, you do not need a function. You only need to change the one line specified between the comments. Which group of consecutive elements should you remove so that the only elements left, sum to 10?

1 Like

elements from 1 to 4

Thanks, it worked!

I have now updated the Hints/Solutions topic to reflect the changes recently made to this challenge.

1 Like