An alert is shown to the user and errors are logged to the console. Also reformat the function code style.