+ 1
Text display
why whenever my variable win is not displaying whenver my first buttons points are over 99 https://code.sololearn.com/W4x0iZQZVmv2/?ref=app
6 Answers
+ 6
I think it's because "if block" only gets executed only once in the starting. You need to check for if condition (your logic) whenever a button is clicked.
One way could be putting the if block in a function and then calling function in button1f()
https://code.sololearn.com/Wem79j38FRDt/?ref=app
+ 3
Your Mom i am still learning and don't know much about css đ
+ 2
// in JS
alert("HOW TO PLAY: this is a multiplayer game. requires 2 people to play. you must click on your side to get 5 points. ")
const pt1 = document.getElementById("points1"),
pt2 = document.getElementById("points2"),
txt = document.getElementById("text");
let points1 = 0, points2 = 0, GmOver = false;
let win = (p) => `Player ${p} Wins!!!`;
function button1f() {
if (!GmOver) {
pt1.innerText = ++points1;
chk();
}
}
function button2f() {
if (!GmOver) {
pt2.innerText = ++points2;
chk();
}
}
function newGamef() {
GmOver = false;
pt1.innerHTML = points1 = 0;
pt2.innerHTML = points2 = 0;
}
chk = () => {
if(points1 >= 5) {
txt.innerText = win(1);
GmOver = true;
} else if(points2 >= 5) {
txt.innerText = win(2);
GmOver = true;
}
}
+ 1
Sandeep i found that urs worked. so i put my if statement inside the button1f() function and that also works. thanks
+ 1
Just move
If(point* === 50){ ... } else {...}
Above i.e. before
If(point* >99) { ... }
In both click function
i.e. else statement was resetting innerHTML to ""