JavaScripts simplest coinflip function?

JavaScripts simplest coinflip function?

This is just a very short post, but this is the absolute simplest JavaScript code I have made, for a coinflip function

const flip = () => {
  return ['Heads', 'Tails'][Math.floor(Math.random() * 2)];
}
console.log(flip());

How simple is that?
We define a function that simply returns Heads or Tails when called.

Follow me on Twitter: @GeirAndersen and also follow my Twitter bot @CodeLogBot. CodeLogBot retweets and likes tweets that contain the hashtag javascript =)

Leave a Reply

Your email address will not be published. Required fields are marked *