How can I make setInterval run faster each time the user clicks ("#header). I have tried several methods and cannot seem to work out a solution

<!DOCTYPE html>


    <h1 id='heading'> Try and click me 10 times.</h1>

    <script src=''></script>

        var leftOffset = 0;
        var topOffset = (200, 0);
        var rightOffset = 200;
        var toTheTop = (0, 200);
        var counter = 10;
        var congrats = "Congrats you Win!"

        var moveHeading = function() {
                left: leftOffset

            if (leftOffset > 200) {
                   top: topOffset,
                    left: 200
            if (topOffset > 200) {
                     top: 200
             if (rightOffset < 0) {
        if (toTheTop < 0){
      leftOffset = 0,
        topOffset = (200, 0),
         rightOffset = 200,
          toTheTop= (200);

   var ghost = function () {

    var nuts = function () {
        if (counter < 8)
{    clearInterval(cc)   }
   if (counter === 9){
      var cc = setInterval(moveHeading,10)
        if (counter < 8)
{    clearInterval(cc)   }
   var x = setTimeout(nuts,20)

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Instead of using setInterval you can set a global variable time and use setTimeout(...,time). You can then lower time everytime nuts() gets run. You will also have to add setTimeout(..., time) inside yourmoveHeading`.

Hey thanks man. It looks much better.

Okay so I did what you suggested and it does work. However The problem I am having now is stopping it. I know its clearTimeout. However because the timeout function is inside move heading isn’t it just repeating itself. How do I make it stop and display congrats after the counter reaches 1. Thanks for you help so far.this is challenge is from Javascript for kids. page 166

You could do something like this (in moveHeading):

if(counter > 1){
  setTimeout(moveHeading, time);

Oh my god, Thank you so much. I can finally move on. Thank you so much. Happy fourth of July. I can’t believe it was that easy. but in hind sight /////it totally makes sense.