#SOLVED -JS buttons and functions

8 messages · Page 1 of 1 (latest)

severe crest
#

Hey all, there's something funny that happened to me 10mins ago w/ the basketball score project.

When I click on the "+1" button for Home team the result is 1, which is good. However, when I click on the Guest button "+1" the result is 2.

It seems that the guest button carries on whatever the home button is ending, and vice versa!

If I click on 2 for home, then I click on 2 for guest the result is 4. the +3 button does the same, the result is 3 for home, and 6 for guest lol. I tried to Google the issue, however, I'm not sure what to look for exactly.

let countOne = document.getElementById("count-el1");
let countTwo = document.getElementById("count-el2");
let count = 0;

function addingHome1() {
count += 1;
countOne.textContent = count;
}

function addingGuest1() {
count += 1;
countTwo.textContent = count;
}

edgy ermine
#

Seems you only have one count variable. so, baskets thrown by both teams are counted.

severe crest
#

Then I should creat two count variables?

#

different from each other?

edgy ermine
#

jep

#

I mean, you are counting two different things, right? If you were counting apples and oranges, you would have two counts, too. One for apples, one for oranges.

severe crest
#

I can't believe I missed this logic. Thanks, Chris, it works correctly now.

#

SOLVED -JS buttons and functions