+ 1
Javascrip code bit run link
I have made a javascript game and i want to show a <a href="">try again</a> link that lets the user try again. Normally i 'd leave the link empty and it just reloads the page, but that doesn't work in the code bit. anyone who can help me make a try again button/link that runs the code again from the start? https://www.sololearn.com/compiler-playground/WxZw910i6r78
6 Respuestas
+ 4
Kevin Kraaijveld
There may be different solutions and its better to write down each steps that you want to Implement and creat an algorithm for your program.
I can share my thoughts which I did previously with an guess Number program which it has an again functionality.
#Solution
1. Create a button with any inner text and with a specific identifier, for its selection in Javascript.
2. In Javascript selecte that btn and call the addEventListener() method to add a specific event and a call back function.
Note: addEventListener expects two arguments an event and a callback function to execute when the event fired.
3.the important step is the call back function which you have to setup all of your app to default Ex. Rest the marks... .
//reset functionality sudo code😊
document.querySelector("#again").addEventListener("click",
function (){
//Your logic
});
the link of your code is not clickable
+ 2
Please share the code
+ 2
Kevin Kraaijveld
how about just using a function to toggle the hidden elements back to their initial state?
instead of <a href= "">
use instead
<p onclick="reset()">Try again</p>
and define reset as
function reset(){
document.body.style.background = "linear-gradient(#00f,#00c);";
nums.style.display = "block";
h1.style.display = "none";
terug.style.display = "none";
document.getElementById('h1').innerHTML = '';
document.getElementById('result').innerHTML = '';
document.getElementById('right').innerHTML = '';
}
+ 2
Kevin Kraaijveld
fun idea. I made a simpler version based on your code, as well as a popup version more closely following your original concept.
https://code.sololearn.com/WQZC1ax5uQ46/?ref=app
https://code.sololearn.com/Wz8ginVaN4vc/?ref=app
+ 1
Kevin Kraaijveld
btw, you could add your code so it can be seen by others using the insert code button. Click the + insert button that is available when you are posting and navigate to your code repo in Sololearn.
I had to visit your profile to view your code.
I also had this problem in Sololearn. Simply refreshing the page would give you a blank page. So I gave up on that method a long time ago.
I am posting your code below, so other members could give perhaps better solutions.
https://code.sololearn.com/WxZw910i6r78/?ref=app