Hello Cody,
I recommend always using curly braces around the single-statement body of if/else/for/while statements if you are going to place the single statement on the next line. That is, instead of this:
.. use this:
The reason for always using curly braces is that there is less risk of confusion. Especially the way that you have the JavaScript code indented, it makes it look like the
document.write() calls and switch statement are within the else block, but in fact they are not.
Another approach is to place the single statement on the same line, like this:
This also helps avoid the risk of confusion.
Recently, there was an infamous security bug nicknamed "gotofail", which you can read about here:
https://www.imperialviolet.org/2014/02/22/applebug.html
The problem was that an extra
goto fail; line was added, meaning that control would always go to the failure/clean-up code:
.. because this is syntactically identical to:
Maybe if curly braces were used around the if statements' single-statement bodies, then the error would not have occurred.
Daniel