Fix jshint warnings

Since nobody ran jshint on our js code, there are some warnings,
including at least one bug.

Change-Id: Ied755e8a38b3b34273f3e5d40bcbeb502b3b9783