+ 1

Why is the code playground text keep popping up?

Link here : https://sololearn.com/compiler-playground/WISeSOQPq23c/?ref=app

11th Jun 2025, 4:16 PM
Brian O'Connell
Brian O'Connell - avatar
20 ответов
+ 3
Thanks Lisa
11th Jun 2025, 4:46 PM
Brian O'Connell
Brian O'Connell - avatar
+ 2
Remove the alerts from your function. You can put them elsewhere. At the moment, you've programmed them to appear when a user clicks the button.
11th Jun 2025, 4:45 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Thanks Ausgrindtube
11th Jun 2025, 4:46 PM
Brian O'Connell
Brian O'Connell - avatar
+ 2
You've giving every button the onclick attribute and you've put alerts inside the targeted changeBackgroundColor function. Thus each time you click a button it calls the function and the code runs. To fix the issue Remove the alerts from the function like this. function changeBackgroundColor(color) { document.body.style.backgroundColor = color } alert("This is a demo of Random files") alert("we will be updating this every week")
11th Jun 2025, 4:48 PM
Chris Coder
Chris Coder - avatar
+ 2
Thanks Chris Coder
11th Jun 2025, 4:52 PM
Brian O'Connell
Brian O'Connell - avatar
+ 2
no, i can't :) i am not a staff member of sololearn
11th Jun 2025, 6:38 PM
Lisa
Lisa - avatar
+ 1
the alerts come up whenever one presses a button because the alerts are inside the color change function. what behavior do you intend instead? and why do you need to define new classes for each button when all buttons are styled the same? https://www.sololearn.com/discuss/3330302/?ref=app
11th Jun 2025, 4:29 PM
Lisa
Lisa - avatar
+ 1
It is the alert() that pops up.
11th Jun 2025, 4:38 PM
Lisa
Lisa - avatar
+ 1
the alerts come up whenever one presses a button ***because*** the alerts are ***inside** the color change function. move the alerts outside of the color change function.
11th Jun 2025, 4:44 PM
Lisa
Lisa - avatar
+ 1
yes, one can make a game from html, css, javascript
11th Jun 2025, 4:54 PM
Lisa
Lisa - avatar
+ 1
Be helpful in the community and someone from the mentorship team will notice your efforts and recommend you to the team leader. You can learn more here. https://www.sololearn.com/en/Sololearn-Mentors
11th Jun 2025, 5:18 PM
Chris Coder
Chris Coder - avatar
0
Click the start button then the load game button and you'll see that the playground code keeps popping up
11th Jun 2025, 4:33 PM
Brian O'Connell
Brian O'Connell - avatar
0
Yeah but it pops up every time you press a button
11th Jun 2025, 4:39 PM
Brian O'Connell
Brian O'Connell - avatar
0
When I want it to only pop up once and not on all the buttons
11th Jun 2025, 4:40 PM
Brian O'Connell
Brian O'Connell - avatar
0
Ok
11th Jun 2025, 4:45 PM
Brian O'Connell
Brian O'Connell - avatar
0
Also what are you doing ?
11th Jun 2025, 4:52 PM
Brian O'Connell
Brian O'Connell - avatar
0
And also can you make a functioning game with just HTML CSS AND JAVASCRIPT?
11th Jun 2025, 4:53 PM
Brian O'Connell
Brian O'Connell - avatar
0
Thanks cause your helping me make it right now
11th Jun 2025, 5:10 PM
Brian O'Connell
Brian O'Connell - avatar
0
Also Chris coder how do you become a mentor?
11th Jun 2025, 5:13 PM
Brian O'Connell
Brian O'Connell - avatar
0
Lisa wait you can make me a mentor?
11th Jun 2025, 5:53 PM
Brian O'Connell
Brian O'Connell - avatar