+ 1
How to make code restart?
If i were to have an if statement at the end of my code asking if the person wants to do something again (eg. Restart the code from the top), how would i do that? (no, not as a loop) https://code.sololearn.com/WLNaQDATh3O8/?ref=app I want to give them a confirm popup box asking them if they want to go again, i know how to schedule the box so it waits a while before it pops up, but i dont know how to tell it to restart eg. if (res == true){ ???? }
13 ответов
+ 4
Hi Stephen Van Der Westhuizen,
One way to accomplish this is to wrap the Javascript code in a function that execute the code on a onclick attribute.
Have a look at the changes, hope it helps👍😊
https://code.sololearn.com/W62LxqloWTTI/?ref=app
+ 3
+ 3
Stephen Van Der Westhuizen made it little bit more readable now.
🌴Vincent Berger🌴 for perfection add <br> or \n to results.
+ 3
Kyle Stevenson my words :D
Just, there should be <br> instead of \n.
+ 2
🌴Vincent Berger🌴 Yeah, good now.
You have better solution than me but i was trying to stay at confirm box.
+ 2
🌴Vincent Berger🌴 I made a minor change so that the text output adds a "<br>" at the end of each computation
https://code.sololearn.com/WpJTj68mups2/?ref=app
+ 2
🌴Vincent Berger🌴 thank you! A button would've been an easy solution, you were a big help!
+ 2
Kyle Stevenson Perfect 😄
+ 1
🌴Vincent Berger🌴 But the button disappears after first calculation
+ 1
Maneren, fixed!
0
You could put all of the code that's to be repeated into a while loop. For example:
while (true) {
/* your code here */
if (user doesn't wish to continue) {
break;
}
}
0
Maneren, i see..
Should be good now👍
0
Maneren, thank you, it was a little confusing looking through it, but i saw what you did