JSFiddle - React, Tailwind, and code Playground

by lexingtonpenguins

JavaScript

alert("Hello!");

var userReady = prompt("Are you ready for a simulation of 1,000 coin flips?! So probability. Much randomness.");

var heads = 0;

var tails = 0;

if (userReady.toLowerCase() === "yes") {
    for (i = 0; i <= 1000; i++) {
        var coinFace = Math.floor(Math.random() * 2);
        if (coinFace === 0) {
            heads++;
        } else {
            tails++;
        }
    }
} else {
    confirm("Oh come on, live a little!");
    var comeOn = prompt("Are you ready now?");
    if (comeOn.toLowerCase() === "yes") {
        for (j = 0; j <= 1000; j++) {
            var coinFace = Math.floor(Math.random() * 2);
            if (coinFace === 0) {
                heads++;
            } else {
                tails++;
            }
        }
    } else {
        confirm("Where is your sense of adventure?");

    }


    confirm("I came up heads " + heads + " times!");
    confirm("I came up tails " + tails + " times!");