+ 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

1st Sep 2022, 5:48 PM
Junior
Junior - avatar
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
1st Sep 2022, 6:06 PM
Sandeep
Sandeep - avatar
+ 3
Your Mom i am still learning and don't know much about css 😅
2nd Sep 2022, 5:53 AM
Sandeep
Sandeep - avatar
+ 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; } }
1st Sep 2022, 6:24 PM
SoloProg
SoloProg - avatar
+ 1
Sandeep i found that urs worked. so i put my if statement inside the button1f() function and that also works. thanks
1st Sep 2022, 6:39 PM
Junior
Junior - avatar
+ 1
SoloProg Sandeep im trying to make it so whenever my 1st button it make the text in a straight line. i tried using word-wrap: nowrap; but its not working i also tried using flex
1st Sep 2022, 6:51 PM
Junior
Junior - avatar
+ 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 ""
3rd Sep 2022, 2:20 PM
Abdul Samad
Abdul Samad - avatar