Javascript Sandbox:
Inspired by
Simone Vittori's real time editor.
EXECUTE
CLEAR CONSOLE
TERMINATE
SAVE
Console log:
//Execute by pressing CTRL! log.textContent = '' // Clear the console log. var startingHeight = 25 var fallTime = 0 console.log('Your hailstone starts at ' + startingHeight + ' meters... <br>Hailstone algorithm... <br>GOOOOOO!!!') function hailstone(h) { fallTime++ console.log(h + ' m') if (h <= 1) { console.log('Thunk!<br>Your hailstone hit the ground after ' + fallTime + ' seconds.') return } else { // Divide by 2 if h is even, otherwise multiply by 3 and add 1: if (h % 2 == 0) h /= 2 else h = h*3 + 1 // Sleep for 100 milliseconds, then run this function again: setTimeout(() => { hailstone(h) }, 100); } } hailstone(startingHeight) // Code run after hailstone() will run before the timeouts are finished! // This is because setTimeout() puts the calls that hailstone() makes to itself on a different thread. // This is also why terminating the main thread doesn't stop the hailstone.