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 =)