Skip to content
Advertisement

Adding a number to number results in NaN in my program. WHY?

I am trying to add secondsPassed to timePassed but when doing so I get NaN.

I can’t find anything wrong so why is timePassed = NaN when adding secondsPassed to it?

JavaScript

Advertisement

Answer

You don’t seem to pass timeStamp argument to gameLoop() function. Passing it fixes the issue. Also make sure, your oldTimeStamp is initialized.
+new Date() is a way to create a timestamp from Date object.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement