+ 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){ ???? }

6th Jan 2019, 12:06 AM
Stephen Van Der Westhuizen
Stephen Van Der Westhuizen - avatar
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
6th Jan 2019, 12:17 AM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
6th Jan 2019, 12:16 AM
Maneren
Maneren - avatar
+ 3
Stephen Van Der Westhuizen made it little bit more readable now. 🌴Vincent Berger🌴 for perfection add <br> or \n to results.
6th Jan 2019, 12:30 AM
Maneren
Maneren - avatar
+ 3
Kyle Stevenson my words :D Just, there should be <br> instead of \n.
6th Jan 2019, 12:31 AM
Maneren
Maneren - avatar
+ 2
🌴Vincent Berger🌴 Yeah, good now. You have better solution than me but i was trying to stay at confirm box.
6th Jan 2019, 12:27 AM
Maneren
Maneren - avatar
+ 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
6th Jan 2019, 12:30 AM
Kyle Stevenson
Kyle Stevenson - avatar
+ 2
🌴Vincent Berger🌴 thank you! A button would've been an easy solution, you were a big help!
6th Jan 2019, 12:30 AM
Stephen Van Der Westhuizen
Stephen Van Der Westhuizen - avatar
+ 2
Kyle Stevenson Perfect 😄
6th Jan 2019, 12:35 AM
Maneren
Maneren - avatar
+ 1
🌴Vincent Berger🌴 But the button disappears after first calculation
6th Jan 2019, 12:19 AM
Maneren
Maneren - avatar
+ 1
Maneren, fixed!
6th Jan 2019, 12:33 AM
Kyle Stevenson
Kyle Stevenson - avatar
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; } }
6th Jan 2019, 12:13 AM
Kyle Stevenson
Kyle Stevenson - avatar
0
Maneren, i see.. Should be good now👍
6th Jan 2019, 12:24 AM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
0
Maneren, thank you, it was a little confusing looking through it, but i saw what you did
6th Jan 2019, 12:27 AM
Stephen Van Der Westhuizen
Stephen Van Der Westhuizen - avatar