title: How do I run 1 of 3 javascript functions randomly?
body: <p>I want to show a random image to a page visitor, then only show that same image to the same visitor until the cookie expires.</p>
  
  <p>Everything works properly but I'm stuck on the initialization.</p>
  
  <p>Basically, if there is no cookie set, I need to run 1 of 3 functions randomly.
  How would I go about choosing the one of 3 functions at random and running it?</p>
  
  <pre><code>$(document).ready(function() {      
  var cookie = readCookie("boatColor");
  if (!cookie) {
    console.log('Run one of 3 Functions Randomly');
    } else if (cookie == "boatRed") {
      showRedBoat();
    } else if (cookie == "boatWhite") {
      showWhiteBoat();
    } else if (cookie == "boatBlue") {
      showBlueBoat();
    }
  }); 
  
  
  function showRedBoat() {
      var newSrc = ""; 
        var myText = "";
      newSrc = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/500458/copeland_boat_red.jpg"; 
          myText = "&lt;h3&gt;You've got the Red Boat!&lt;/h3&gt;";
      theImage.src = newSrc; 
      theDesc.innerHTML = myText;
      createCookie("boatColor", 'boatRed', 0.00034722222);
  }
  
  function showWhiteBoat() {
      var newSrc = ""; 
        var myText = "";
      newSrc = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/500458/copeland_boat_white.jpg"; 
          myText = "&lt;h3&gt;You've got the White Boat!&lt;/h3&gt;";
      theImage.src = newSrc; 
      theDesc.innerHTML = myText;
      createCookie("boatColor", 'boatWhite', 0.00034722222);
  }
  
  function showBlueBoat() {
      var newSrc = ""; 
        var myText = "";
      newSrc = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/500458/copeland_boat_blue.jpg"; 
          myText = "&lt;h3&gt;You've got the Blue Boat!&lt;/h3&gt;";
      theImage.src = newSrc; 
      theDesc.innerHTML = myText;
      createCookie("boatColor", 'boatBlue', 0.00034722222);
  }
  
  function createCookie(name,value,days) {
      if (days) {
          var date = new Date();
          date.setTime(date.getTime()+(days*24*60*60*1000));
          var expires = "; expires="+date.toGMTString();
      }
      else var expires = "";
      document.cookie = name+"="+value+expires+"; path=/";
  }
  
  function readCookie(name) {
      var nameEQ = name + "=";
      var ca = document.cookie.split(';');
      for(var i=0;i &lt; ca.length;i++) {
          var c = ca[i];
          while (c.charAt(0)==' ') c = c.substring(1,c.length);
          if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
      }
      return null;
  </code></pre>
  
  <p>} </p>
  
  <p>Codepen Link: <a href="https://codepen.io/nolaandy/pen/awgoQM" rel="nofollow noreferrer">https://codepen.io/nolaandy/pen/awgoQM</a> </p>