setInterval runs a function after the specified amount of time.
If you clear the interval before that time is up, no function will be run because the setInterval will be canceled out before it can run it.
So what you can do is run the clearInterval within the function you are calling, so that way the setInterval gets cleared after your function has already been called
though wait is defined before the interval is called, its the interval that actually runs wait, and is THEN that myInterval can be cleared and stopped… after its been run (which would happen after its been defined)