title: How can I create a variable condition as a parameter in javascript?
body: <p>I want to test how many red/black/even/odd comes up in a row in the game of roulette. </p>
  
  <p>The following function will loop through a list of spins n and give how many times in a row red won and lost. The same function can be used for all the other types of even wins however the check is different </p>
  
  <pre><code>color[n[i]] == "red"
  </code></pre>
  
  <p>I want to pass a different check into this function to test for evens </p>
  
  <pre><code>n[i]%2 == 0
  </code></pre>
  
  <p>Can this be done?</p>
  
  <pre><code>function test(n)
  {
      var wins = parseInt(0);
      var losses = parseInt(0);
  
      for(var i=0;i&lt;n.length;i++)
      {
          if(color[n[i]] == "red")
          {
              wins += 1 
              losses = 0
          }
          else
          {
              wins = 0
              losses += 1
          }
  
      }
  .
  .
  .
  </code></pre>
  
  <p>PART 2 </p>
  
  <p>This is the full code. If you click the 'Enter Spins' button and the 'Toggle Number Pad' button, then add the number 8 twice, then 3 alerts will display. </p>
  
  <p>I can not seem to get the the 3 messages to show up on separate lines. I tried some examples, but it always adds the line return before the last message. 
  Do you know how to get the multiple messages on separate lines?</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;style&gt;
  .bntcal {
      padding: 10px 10px 10px 10px;
      margin: 10px;
  }
  .bntcaladd {
      padding: 10px 10px 10px 10px;
      margin: 10px;
  }
  
  .bntshow{
      padding: 5px 5px 5px 5px;
      margin: 5px;
      width: 10%;
  }
  .spanhide {
      display: none;
  }
  .bell {
      float:left;
      display: none;
  }
  
  &lt;/style&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  var wheel0 = [37,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26];
  var wheel00 = [37,28,9,26,30,11,7,20,32,17,5,22,34,15,3,24,36,13,1,38,27,10,25,29,12,8,19,31,18,6,21,33,16,4,23,35,14,2];
  var wheel = wheel00;
  var wColor = "";
  var numbers = [];
  var color = [];
  
  
  
  $(document).ready(function(){
  
      // --- Menu Buttons
      $("#enterSpins").click(function(){
          $("#divSpins").show();
          $("#divAlerts").hide();
          $("#divHowTo").hide();
      });
  
      $("#setAlert").click(function(){
          $("#divAlerts").show();
          $("#divSpins").hide();
          $("#divHowTo").hide();
      });
  
      $("#howTo").click(function(){
          $("#divHowTo").show();
          $("#divSpins").hide();
          $("#divAlerts").hide();
  
      });
  
      // ---- Sub Buttons
      $("#enterPad").click(function(){
          $("#showSpinsPad").toggle();
          $("#clearBox").toggle();
          $("#clearBox1").toggle();
          if(!$("#showSpinsPad").is(":hidden"))
          {
              $("#spins").prop("disabled", true)
          }
          else
          {
              $("#spins").prop("disabled", false)
          }
  
      }); 
  
      $(".bntcal").click(function(){
          $("#currentSpin").text($("#currentSpin").text()+$(this).val())
          if ($("#currentSpin").text().length &gt; 2)
          {
              $("#currentSpin").text($(this).val())
          }    
      });
  
  
      $("#clear").click(function(){
          $("#currentSpin").text("")
      });
  
      $("#add").click(function(){
  
          getWheel()
          currentSpin = $("#currentSpin").text()
          if(currentSpin.length &gt; 0)
          {
              if ($("#spins").val().length &gt; 0)
              {
                  $("#spins").val($("#spins").val() + ", ");
              }
              if(parseInt(currentSpin)&lt;37)
              {
                  $("#spins").val($("#spins").val() + currentSpin);
              }
              if(parseInt(currentSpin) == 37)
              {
                  $("#spins").val($("#spins").val() + "0");
              }
              if(parseInt(currentSpin) == 38)
              {
                  $("#spins").val($("#spins").val() + "00");
              }
              if(parseInt(currentSpin)&gt;38)
              {
                  $("#spins").val($("#spins").val() + "0");
              }
  
              $("#currentSpin").text("") 
          }
  
          var n = GetUserNumbers();
          run(n)
      });
  
      $("#undo").click(function(){
          var n = GetUserNumbers();
  
          if (n.length&gt;0)
          {
              n.pop();
          }
          $("#spins").val(n)
          run(n)
      });
  
      $("#clean").click(function(){
          $("#spins").val("")
      });
  
      $("#run").click(function(){
          var n = GetUserNumbers();
          run(n)
      });
  
  });
  // ---------------------------------------------------------------
  // --------------------- FUNCTIONS -------------------------------
  // ---------------------------------------------------------------
  
  function run(n)
  {
  
      $("#alert").text("")
  
      // Evens
      var conditions = ['color[n] == "red"','color[n] == "black"','n%2 == 0 &amp;&amp; n&lt;37','n%2 == 1 &amp;&amp; n&lt;37','n &gt; 18 &amp;&amp; n&lt;37','n &lt; 19 &amp;&amp; n&gt;0']
      var checklocation = ['Red','Black','Even','Odd','High','Low']
      var idWins = "#evenwin"
      var idLosses = "#evenloss"
  
      checkCondition(n, conditions, checklocation, idWins, idLosses)
  
      // Dozens
      var conditions = ['n%3 == 1','n%3 == 2','n%3 == 0','n&gt;=1 &amp;&amp; n&lt;=12','n&gt;=13 &amp;&amp; n&lt;=24','n&gt;=25 &amp;&amp; n&lt;=36']
      var checklocation = ['Row 1 [1,2,3..]','Row 2 [2,3,4..]','Row 2 [3,6,9..]','Dozen 1 [1-12]','Dozen 1 [13-24]','Dozen 1 [25-36]']
      var idWins = "#dozenwin"
      var idLosses = "#dozenloss"
  
      checkCondition(n, conditions, checklocation, idWins, idLosses)
  }
  
  function checkCondition(n, conditions, checklocation, idWins, idLosses)
  {
      for(var i=0; i&lt;conditions.length; i++)
      {
          var check = function(n){ if(conditions[i]){ return true; } else { return false; }}
          var wins = checkWins(n, check)
          var losses = checkLosses(n, check)
          if(wins &gt;= $(idWins).val()) { $("#alert").text($("#alert").text()+" "+checklocation[i]+" loses "+wins+" times in a rows.&lt;br/&gt;")}
          if(losses &gt;= $(idLosses).val()) { $("#alert").text($("#alert").text()+" "+checklocation[i]+" loses "+losses+" times in a rows.&lt;br/&gt;")}
      }
  }
  
  function checkWins(n, condition)
  {
      var wins = parseInt(0);
      for(var i=0;i&lt;n.length;i++)
      {
          if(condition(n[i]))
          {
              wins += 1 
          }
          else
          {
              wins = 0
          }   
      }
  
      return wins 
  }
  
  function checkLosses(n, condition)
  {
      var losses = parseInt(0);
      for(var i=0;i&lt;n.length;i++)
      {
          if(condition(n[i]))
          {
              losses = 0
          }
          else
          {
              losses += 1
          }
      }
      return losses
  }
  
  $.fn.multiline = function(text){
      this.text(text);
      this.html(this.html().replace(/\n/g,'&lt;br/&gt;'));
      return this;
  }
  
  
  function getWheel()
  {
      if($("input[name=wheel]:checked").val()=="0")
      {
          wheel = wheel0
      }
      else
      {
          wheel = wheel00
      }
      color = GetColor(wheel)
  }
  
  function reset()
  {
      evenwins = parseInt(0);
  }
  function GetUserNumbers()
  {
      var n = $("#spins").val().split(",");
  
      for(var x=0; x&lt;n.length; x++)
      {
          if(n[x].trim() == "0")
          {
              n[x] = "37";
          }
          if(n[x].trim() == "00")
          {
              n[x] = "38";
          }
          n[x] = parseInt(n[x].trim());
      }
      return n;
  }
  
  function GetColor(wheel)
  {
      var color = Array();
      if(wheel.length==37)
      {
          color[1] = "red";
          color[2] = "black";
          color[3] = "red";
          color[4] = "black";
          color[5] = "red";
          color[6] = "black";
          color[7] = "red";
          color[8] = "black";
          color[9] = "red";
          color[10] = "black";
          color[11] = "black";
          color[12] = "red";
          color[13] = "black";
          color[14] = "red";
          color[15] = "black";
          color[16] = "red";
          color[17] = "black";
          color[18] = "red";
          color[19] = "red";
          color[20] = "black";
          color[21] = "red";
          color[22] = "black";
          color[23] = "red";
          color[24] = "black";
          color[25] = "red";
          color[26] = "black";
          color[27] = "red";
          color[28] = "black";
          color[29] = "black";
          color[30] = "red";
          color[31] = "black";
          color[32] = "red";
          color[33] = "black";
          color[34] = "red";
          color[35] = "black";
          color[36] = "red";
          color[37] = "green";
      }
      if(wheel.length==38)
      {
          color[1] = "red";
          color[2] = "black";
          color[3] = "red";
          color[4] = "black";
          color[5] = "red";
          color[6] = "black";
          color[7] = "red";
          color[8] = "black";
          color[9] = "red";
          color[10] = "black";
          color[11] = "black";
          color[12] = "red";
          color[13] = "black";
          color[14] = "red";
          color[15] = "black";
          color[16] = "red";
          color[17] = "black";
          color[18] = "red";
          color[19] = "red";
          color[20] = "black";
          color[21] = "red";
          color[22] = "black";
          color[23] = "red";
          color[24] = "black";
          color[25] = "red";
          color[26] = "black";
          color[27] = "red";
          color[28] = "black";
          color[29] = "black";
          color[30] = "red";
          color[31] = "black";
          color[32] = "red";
          color[33] = "black";
          color[34] = "red";
          color[35] = "black";
          color[36] = "red";
          color[37] = "green";
          color[38] = "green";
      }
      return color;
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  Toggle Displays&lt;/br&gt;&lt;br/&gt;
  &lt;div &gt;
  &lt;button class="bntshow" id="enterSpins"&gt;Enter Spins&lt;/button&gt;&lt;br/&gt;
  &lt;button class="bntshow" id="setAlert"&gt;Set Alerts&lt;/button&gt;&lt;br/&gt;
  &lt;button class="bntshow" id="howTo"&gt;How To&lt;/button&gt;&lt;br/&gt;
  &lt;input type="radio" name="wheel" value="0"&gt;0 Wheel&lt;br/&gt;
  &lt;input type="radio" name="wheel" value="00" checked&gt;00 Wheel&lt;br/&gt;
  &lt;/div&gt;&lt;br/&gt;
  &lt;div id="alert"&gt;&lt;/div&gt;
  &lt;hr&gt;
  
  
  &lt;!-- Enter Spins --&gt;
  &lt;span class="spanhide" id="divSpins"&gt;
  &lt;button class="bntcaladd" id="enterPad"&gt;Toggle Numberpad&lt;/button&gt;&lt;br/&gt;
  &lt;br/&gt;
  
  &lt;span class="spanhide" id='showSpinsPad'&gt;
  &lt;br/&gt;
  &lt;button class="bntcal" id="calculator" value="0"&gt;0&lt;/button&gt;
  &lt;button class="bntcal" id="calculator" value="00"&gt;00&lt;/button&gt;&lt;br/&gt;
  &lt;button class="bntcal" id="calculator" value="1"&gt;1&lt;/button&gt;
  &lt;button class="bntcal" id="calculator" value="2"&gt;2&lt;/button&gt;
  &lt;button class="bntcal" id="calculator" value="3"&gt;3&lt;/button&gt;&lt;br/&gt;
  &lt;button class="bntcal" id="calculator" value="4"&gt;4&lt;/button&gt;
  &lt;button class="bntcal" id="calculator" value="5"&gt;5&lt;/button&gt;
  &lt;button class="bntcal" id="calculator" value="6"&gt;6&lt;/button&gt;&lt;br/&gt;
  &lt;button class="bntcal" id="calculator" value="7"&gt;7&lt;/button&gt;
  &lt;button class="bntcal" id="calculator" value="8"&gt;8&lt;/button&gt;
  &lt;button class="bntcal" id="calculator" value="9"&gt;9&lt;/button&gt;&lt;br/&gt;
  &lt;button class="bntcaladd" id="clear"&gt;Clear&lt;/button&gt;
  &lt;button class="bntcaladd" id="add"&gt;ADD&lt;/button&gt;&lt;span id="currentSpin"&gt;&lt;/span&gt;
  &lt;br/&gt;
  &lt;button class="bntcaladd" id="undo"&gt;Undo&lt;/button&gt;&lt;br/&gt;
  &lt;span id="currentSpin"&gt;&lt;/span&gt;
  &lt;br/&gt;
  &lt;/span&gt;
  &lt;span id="clearBox"&gt;Enter roulette numbers separated by a comma&lt;/span&gt;&lt;br/&gt;
  &lt;textarea rows="10" cols="50" id="spins"&gt;&lt;/textarea&gt;&lt;br/&gt;&lt;br/&gt;
  &lt;span id="clearBox1"&gt;
  &lt;button id="clean"&gt;Clear Box&lt;/button&gt;
  &lt;button id="run"&gt;Run&lt;/button&gt;
  &lt;/span&gt;
  
  &lt;/span&gt;
  
  &lt;!-- Set Alerts --&gt;
  &lt;span class="spanhide" id="divAlerts"&gt;
  &lt;h2&gt;Evens&lt;/h2&gt;
  &lt;input type="text" id="evenwin" value="2"&gt; Wins in a row&lt;br&gt;
  &lt;input type="text" id="evenloss" value="6"&gt; Losses in a row&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;h2&gt;Dozens&lt;/h2&gt;
  &lt;input type="text" id="dozenwin" value="6"&gt; Wins in a row&lt;br&gt;
  &lt;input type="text" id="dozenloss" value="6"&gt; Losses in a row&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  
  &lt;/span&gt;
  
  &lt;!-- How To --&gt;
  &lt;span class="spanhide" id="divHowTo"&gt;
  How To
  &lt;/span&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>