Skip to content

Conversation

@salman0ansari
Copy link

fix #142

@Nagrom33
Copy link

This only return "1"

@AliFARHAT1
Copy link

AliFARHAT1 commented Oct 27, 2022 via email

@salman0ansari
Copy link
Author

This only return "1"

fixed

@AlePaff
Copy link

AlePaff commented May 14, 2023

You must change from 'round()' to 'floor()'. Otherwise, if a value like 0.84 is rounded with 'round()' to 2 decimal places (0.84 * length = 1.68 -> 2), an index that doesn't exist will be selected. Resulting in an error.

The corrected code would be

let outcomesIndex = Math.floor(Math.random() * outcomes.length);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Flip a coin feature

4 participants