Skip to content
← Back to Community
Flip a Coin 10000 Times!
Profile icon
STCollier

This program will flip a coin as many times as your computer can handle and tell you how many times you get heads or tails.

Edit: lol how did this lame program get 7 13 up-votes

Edit 2: Y'all made me self conscious about my code so I updated it, making the program better.

Edit 3: Also, please don't crucify me, I'm too lazy to style the program.

Also, as @TheDrone7 mentioned, the results are somewhat biased, because the JavaScript Math.random function is given a seed such that the random number is almost always going to be very near to 0.5. So sorry about that, I couldn't think of a way to fix it.

Voters
Profile icon
ShiKage
Profile icon
hg0428
Profile icon
HongweiChen
Profile icon
RileyMears
Profile icon
ADEAR
Profile icon
YilingSun
Profile icon
ObamaStudios
Profile icon
james278
Profile icon
Yoplayer1py
Profile icon
ch1ck3n
Comments
hotnewtop
Profile icon
InvisibleOne
Profile icon
hg0428

Use input type=number so that people can't input letters.
This app is very interesting to use

Profile icon
TheDrone7

Fun fact, the js Math random function is given a seed such that the random number is almost always going to be very near to 0.5

Profile icon
Yoplayer1py

Cool

Profile icon
STCollier

@Yoplayer1py Thanks!

Profile icon
CoderGautamYT

This is so simple and so interesting lol

Profile icon
STCollier

@CoderGautamYT thank you :)

Profile icon
sn236

Nice, I've made some changes - https://coin-flipping-statistics.sn236.repl.co/. (As it was plain)

Profile icon
sojs

@sn236 @STCollier I made one as well. This one has a couple new things.

  1. You really overcomplicated the code... it wont go higher than 10K. I made it go all the way up as high as you want (I have it currently set at 100 Million... no higher bc of lag). I also added a stylesheet. Mine also calculates the ratio of heads to tails to make it easily readable how close it is to even.
Profile icon
STCollier

@sojs Thanks for the tips!! I'll check out your code to see what I should do differently. Also, I wrote this program before I even knew about for loops, so the looping system is just a weird copy from stack overflow.

Profile icon
sojs

ya. loops are a lot better because you can go through them as many times as you want. @STCollier