You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@at0g you are wrong because Math.random() * excuses.length - 1 could give you a negative integer, the proper way is var excuse = excuses[Math.floor(Math.random() * excuses.length)%excuses.length];
The current code is totally fine, your code is wrong.
Math.random returns a number between 0 (inclusive) and 1 (exclusive).
So Math.random() * length can never be equal length, is always lower than length.
That's true @emre1702 , the line of code var excuse = excuses[Math.floor(Math.random() * excuses.length)]; works perfectly fine. No change must be performed. Making my change will cause an error in case that excuses = []
This line: https://github.com/NARKOZ/hacker-scripts/blob/master/nodejs/hangover.js#L33
var excuse = excuses[Math.floor(Math.random() * excuses.length)];
should be:
var excuse = excuses[Math.floor(Math.random() * excuses.length - 1)];
var excuse = excuses[Math.floor(Math.random() * (excuses.length - 1))];
The text was updated successfully, but these errors were encountered: