//STYLE: Debug using the console log

The console log can send you information silently

By now, you have noticed all of the console.log() commands in the code examples.

The console log is where most browsers will record error messages in Javascript code. It is also a place where you can have your code send you messages.

Usually there is a menu item that will display the console log.

Run some code with the console open to see how it can help you debug things. It is like using alerts that you can keep buried in your code that nobody but you (and other developers) will see.

I recommend adding console.log() commands:

You can also type variable names and commands directly into the console, and it will report their values back to you. For example: console.log("numOpponents=" + numOpponents); will print out the current value of numOpponents to the console log.

I am not making console logging mandatory, but you might be crazy not to use it. It makes debugging much more pleasant!

Discover what values your variables hold without console.log()

Inside modern browsers is a Javascript console with a line that allows you to type in commands.

One of the things that it allows you to do is type in variable names so that you can see what is inside.

After you run a piece of code, try typing in the name of your variable directly into the console to see what that variable holds. Powerful!