It is a memory game where you flip two cards so that they are identical. if you have flipped all the identical cards, you win. It is object-oriented programming. I have a method that has to display a number(score of the player) once they have flipped all the cards. But I am stuck and I just can't get the number to be displayed on the screen So in the HTML I just hardcoded the value (see below) And the hard coded value is also not being displayed on the screen
<!-- ---------victory overlay---------- -->
<div id="victory-text" class="overlay-text overlays">
Victory
<div class="overlay-text-small">
Your Score: <span id="score">Hello</span>
</div>
<span class="overlay-text-small">
Click to restart
</span>
</div>
And the result is
but if the HTML is
<!-- ---------victory overlay---------- -->
<div id="victory-text" class="overlay-text overlays">
Victory
<div class="overlay-text-small">
Your Score: <span id="score">123</span>
</div>
<span class="overlay-text-small">
Click to restart
</span>
</div>
The result is
And the javascript is
victory(){
clearInterval(this.countDown)//this stops the timer
this.audioController.victory()//plays the victory sound
this.audioController.stopMusic()//stops the background sound
this.hideCards()//this is flips the cards to their original state
document.getElementById("victory-text").classList.add("visible")//and this makes the overlay visible
let score = document.getElementById("score");
console.log(score)
The CSS code
.overlay-text{
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
justify-content: center;
align-items: center;
z-index: 100;
color: #f19041;
font-family: creepy,serif;
}
.overlay-text.visible{
display: flex;
flex-direction: column;
animation:overlay-grow 500ms forwards;
}
.overlay-text-small{
font-size: 60px;
}
The id ="victory-text" is used in javascript to get that specific overlay(as there are other overlays as well like the game-over-text) in the victory() method
The victory function is called when all the cards are flipped. The number "123" is just a hardcoded value and later I will insert the number(the actual score) dynamically. But the hardcoded value is also not being displayed. Can someone please help me with this? I am just getting started off with javascript
The victory() is called in the cardMatch() method
cardMatch(card1, card2){
this.matchedCards.push(card1)
this.matchedCards.push(card2)
card1.classList.add("matched")
card2.classList.add("matched")
this.audioController.match()
if (this.matchedCards.length === this.cardsArray.length) {
this.victory()
}
}



innerHTMLlike that should work with both numbers and strings. Would you mind posting more of your code, so maybe we can help you out..innerHTML +=will not do math for you. The HTML is only usable as a string with this. If you want to add the score you have to read the value, add the new score and write the new value. Or you keep the score in a variable in general and just output that variable.document.getElementById("victory-text").classList.add("visible")It means that the victory-text isdisplay:none;, right?