1. Your HTML is invalid - for example the <input> should be inside a form - or you should use a <button> tag instead.
2. Modern JavaScript is mostly attached just before the </body> tag so that you don't need to include code to test if the HTML has loaded before trying to interact with it.
I guess if you are stuck with that poorly written page then there isn't much you can do about it for the assignment but you should make sure your own pages use valid HTML and put the JavaScript in the right place.
To actually work out the code you need you should break what you need to do up into manageable pieces and code and test each one separately before combining them together into the finished script.
For example you could start by writing a function that returns the distance a dot is to be moved on a click. You can then display the result of calling that function using an alert and then move on to code and test the next piece of code.
Code:
function takeAStep(){
function stepSize() {return Math.floor(Math.random()*3+1);}
alert(stepSize()); // temporary code to test
}
Next select another piece of what the code needs to do and write a function that does that.