The console.log you uploaded is just a blank file.
The script is messed up in so many places I can't even tell exectly what you were trying to accomplish, but the syntax error is that the last two lines should be before you declare the function. Not that fixing it will accomplish anything.