When you moved the variable declaration into the green function block that goes with the slider change event, you made the speed variable local to that function. If you want to be able to access the variable from anywhere in the program, it needs to be a global variable. That means that you should declare it at the beginning of the program, outside of any other blocks.
Once you declare a variable, you should never declare it again, because you will be making a new variable, not working with the one you already have. So, inside all the the functions that use your global variable
speed, just update the variable with
speed =. Don't declare it by using one of the
I don't see a warning on line 16, but you may have changed the code since then. If you can tell me the new line or take a screen shot, I can take a look.