0

This is my Javascrip file that shows for my tetris game, like in the game the object is to cover a row and have it removed however in the removed squares section it will not work giving me a type error saying squares.splice is not a function

function scoreBoard () {
    for (let i = 0; i < 199; i +=width) {
        const rows = [i, i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9]

        if(rows.every(index => squares[index].classList.contains('taker'))) {
            score +=10
            scoreDisplay.innerHTML = score
            rows.forEach(index => {
                squares[index].classList.remove('taker')
            })
            const removedSquares = squares.splice(i, width)
            console.log(removedSquares)
        }

    }
}
  • 1
    How have you defined the `squares` variable? I'm guessing that it's probably a HTMLCollection of NodeList. – Nick Parsons Apr 21 '23 at 09:02
  • [^ that](https://stackoverflow.com/posts/comments/134160772) was meant to say HTMLCollection **or** NodeList - you get a HTMLCollection if you're using something like `getElementsByClassName()`, and you'll get a NodeList if you're using something like `querySelectorAll()`. Both are array-like, but they're not arrays, so they don't have array methods. You can convert both to arrays though using the spread syntax `...` or `Array.from()` – Nick Parsons Apr 21 '23 at 09:12
  • I'll send you the link to the github file that way you can see it better thanks for your help Nick https://github.com/jk2uman/Simple-Tetris – Killmonger Apr 21 '23 at 14:54
  • 1
    Wait I checked your method your right I forgot to call the Array.from() for my variable thanks for your help Nick it fixed the code its working again – Killmonger Apr 21 '23 at 15:01

0 Answers0