Slider support to display and modify variables

I'm having some good success, but it's not easy. Javascript is ugly and when I make a little typo in my Javascript the KM engine hangs up and I have to Force Quit the KM Engine (with up to 8GB of memory assigned to it). That doesn't make this a good learning experience. It looks like I've solved half the problem because I can get a slider to modify a KM variable immediately, as follows:

The second half of my requirement is to include a loop in the Javascript code that constantly fetches the value of the KM Variable "Range1" and modifies the slide bar to correlate to the value. But I keep hanging the KM Engine, probably because I don't know how to put a pause in the loop to allow the OS to display the new value. Hypothetically I would like the answer to look something like this: (but this causes KME to hang)

Either I'm missing a Javascript statement in this loop to give the OS a chance to display the data, or I'm using the wrong approach with an infinite loop. Any thoughts? I'm proud of myself for getting this far, but I need help.