Reputation: 71
I'd like to add a winning count on top of this existing function but I don't know how. I have very very little knowledge about coding and nobody near me knows either. I hope I can get some help from here. thanks!
Edit: I tried adding the whole code but it won't let me save the edits. However, I put the whole code here:https://codeshare.io/8p63Wj for everyone's reference.
function addPhoto(data, mode) {
// DATA
let userName = data.uniqueId;
let userAvatar = data.profilePictureUrl;
let word = ['Nice going','That’s better than ever','That’s first class work','I’m impressed','Nothing can stop you now','Well done','Good job','You did it','That’s the way','You rock','I knew you could do it','Keep up the good work','That’s clever','Way to go','Outstanding','Tremendous','Fantastic','You are amazing','No one can beat you','You are the chosen one'];
let words = word[Math.floor(Math.random()*word.length)];
// Add
if (mode == "winner")
{
addContent(
`<div style="text-align:center;font-size: 1.25rem;">
<div style='padding-bottom:.25rem;color:#1881FF;'>👏🏻👏🏻 `+words+`</div>
<div style='padding-bottom:.5rem;font-weight: bold;color:#20B601;'>`+userName+` ❗</div>
<div>
<img src="`+userAvatar+`" style="width:135px;height:135px;border-radius: 15px;"/>
</div>
</div>`
);
} else {
addContent(
`<div style="text-align:center;font-size: 1.25rem;">
<div style='padding-bottom:.25rem;'>🎉🎉🎉Thanks🎉🎉🎉</div>
<div style='padding-bottom:.5rem;font-weight: bold;color:#EA0C0C;'>`+userName+`</div>
<div>
<img src="`+userAvatar+`" style="width:135px;height:135px;border-radius: 15px;"/>
</div>
</div>`
);
}
// Sound
playSound(3);
}
Upvotes: 0
Views: 75
Reputation: 747
You could use variables that are "rememberd" outside of the scope of the function. That way the page will still remember the value after the function is done. But you do increase those variables inside the function, every time they win for example.
let plays = 0;
let wins = 0;
let losses = 0;
function addPhoto(data, mode) {
// DATA
let userName = data.uniqueId;
let userAvatar = data.profilePictureUrl;
let word = ['Nice going','That’s better than ever','That’s first class work','I’m impressed','Nothing can stop you now','Well done','Good job','You did it','That’s the way','You rock','I knew you could do it','Keep up the good work','That’s clever','Way to go','Outstanding','Tremendous','Fantastic','You are amazing','No one can beat you','You are the chosen one'];
let words = word[Math.floor(Math.random()*word.length)];
// Add
plays++;
if (mode == "winner")
{
wins++;
addContent('<p>Plays: '+plays+' Wins: '+wins+' Losses: '+losses+'</p>');
} else {
losses++;
addContent('<p>Plays: '+plays+' Wins: '+wins+' Losses: '+losses+'</p>');
}
// Sound
playSound(3);
}
Upvotes: 1