WDI-SEA / game-project-issues

0 stars 0 forks source link

Score not updating #47

Closed shuzel99 closed 3 years ago

shuzel99 commented 3 years ago

What's the problem you're trying to solve?

I want my game to start out with an initial 30 points and add an additional 10 points per collision

Post any code you think might be relevant (one fenced block per file)

const detectHit = () => {
    for (let i = 0; i < fruitCollection.length; i++)
    // console.log(fruitCollection[i])
    if  (
        cart.x < fruitCollection[i].x + fruitCollection[i].width &&
        cart.x + cart.width > fruitCollection[i].x && 
        cart.y < fruitCollection[i].y + fruitCollection[i].height &&
        cart.y + cart.height >= fruitCollection[i].y
    ){
        fruitCollection[i].alive = false
        newScore += 10
        fruitCollection.splice(i, 1) //removes items that have been collided with from canvas
        console.log("Collision Detected")
    } 
}

let score = 30 
pointsUpdate.innerText = " " + score

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

There's no error message but the Points in the game remain at 30. When I try to incorporate the 'newScore' variable into the pointsUpdate nothing in the game shows up at all.

What is your best guess as to the source of the problem?

not sure yet

What things have you already tried to solve the problem?

tried incorporating newScore in a couple different ways including ${newScore} with & without backticks into the pointsUpdate

shuzel99 commented 3 years ago

I lied. There's an error message that says newScore isnt defined

DoireannJane commented 3 years ago

Ah ok! So you're going to want your newScore set to zero since we're adding points to it!

shuzel99 commented 3 years ago

I want the initial amount of points to be 30 then add to 10 more points once a collision is detected

DoireannJane commented 3 years ago

Your interpolation (so it alters the HTML element and renders) should look something like this: Points: ${newScore} (in back tics)

DoireannJane commented 3 years ago

You can set your starting point to 30. That's fine!

shuzel99 commented 3 years ago

I tried the interpolation like that before and nothing renders, not even the fruits