#Basket Ball Score board

16 messages · Page 1 of 1 (latest)

umbral vessel
#

i have an issue with my code

let homeScoreBtnOne = document.getElementById("home-score-btn-1")
let homeScoreEl =document.getElementById("home-score")
let homeScore = 0

function increaseHomeScoreOne(){
homeScore += 1
homeScoreEl.textContent = homeScore
}

let homeScoreBtnTwo = document.getElementById("home-score-btn-2")
let homeScoreEl2 =document.getElementById("home-score")
let homeScore2 = homeScore + 1

function increaseHomeScoreTwo(){
homeScore2 += 2
homeScoreEl2.textContent = homeScore2
}

let homeScoreBtnThree = document.getElementById("home-score-btn-3")
let homeScoreEl3 =document.getElementById("home-score")
let homeScore3 = homeScore + 2

function increaseHomeScoreThree(){
homeScore3 += 3
homeScoreEl3.textContent = homeScore3
}

let guestScoreBtnOne = document.getElementById("guest-score-btn-1")
let guestScoreEl =document.getElementById("guest-score")
let guestScore = 0

function increaseGuestScoreOne(){
guestScore += 1
guestScoreEl.textContent = guestScore
}

let guestScoreBtnTwo = document.getElementById("guest-score-btn-2")
let guestScoreEl2 =document.getElementById("guest-score")
let guestScore2 = 0

function increaseGuestScoreTwo(){
guestScore2 += 2
guestScoreEl2.textContent = guestScore2
}

let guestScoreBtnThree = document.getElementById("guest-score-btn-3")
let guestScoreEl3 =document.getElementById("guest-score")
let guestScore3 = 0

function increaseGuestScoreThree(){
guestScore3 += 3
guestScoreEl3.textContent = guestScore3
}
this is my java script code
i would love it if someone could hepl me. Whenever i click on the +1 button it increases by 1 for the +2 by 2 and also for the +3. But when i go back to click +1 it counts from where the +1 stopped and it does not continue from where the count is as u can see in the short video

fiery holly
#

Looking at these lines (and applies for homeScoreEl3 too):

  let homeScoreBtnTwo = document.getElementById("home-score-btn-2")
  let homeScoreEl2 =document.getElementById("home-score") //Remove this
  let homeScore2 = homeScore + 1 //Change this to homeScore += 1

  function increaseHomeScoreTwo(){
    homeScore2 += 2 //Change this to homeScore += 2
    homeScoreEl2.textContent = homeScore2 //Change this to homeScoreEl.textContent = homeScore
  }

The score for the +1 button press is kept with homeScore, but a different score is kept with homeScore2, and another different score is kept with homeScore3.

To fix this replace all references to homeScore2 and homeScore3 with just homeScore, and remove the declarations for homeScoreEl2 and 3 and just update homeScoreEl (since all of them refer to the same element we don't need to make multiple variables for the same thing)

umbral vessel
#

Thanks so much it worked

fiery holly
#

Glad to help 🙂

umbral vessel
#

I decidet to move another step and make a new game button

#

the new game button is meant to take the score back to zero

#

but i dont know how to do it for the two score both home and guest. I would like someone to help me please

#

This is my java script code for the new game button

#

let newGameBtn = document.getElementById("new-game")
let newGame1 = 0

function newGame(){
homeScore = 0
homeScoreEl.textContent = homeScore
}\

umbral vessel
#

can someone please help me for any ideas on how to fix this

fiery holly
#

You just need to add guestScore = 0, and guestScoreEl.textContent = guestScore to that same function.

Also, I don't think newGame1 is needed

umbral vessel
#

thank you once again for your help

#

it worked

nimble valley
#

hello eveyone, I'm new here and I'm having trouble with getting the style in figma. can anyone kind enough to help me?

unborn meteor
#

ey, did you find a solution?