Generating Random Groups of Elments from an Array Javascript -


hi working on project school , trying generate random groups of names list of names. group size , amount of groups based off users input. have code randomly generate single element array, need grouping. code far. not functioning please thanks

function yeah()          {          var arr = prompt("enter names").split(",")          console.log(arr);          var random = arr[math.floor(math.random() * arr.length)];           document.getelementbyid("h2").innerhtml = random;          }              function groups()         {                var arr = prompt("enter names").split(",");              var random = arr[math.floor(math.random() * arr.length)];              var numelem = document.getelementbyid("input2").value;              (i=0;i <= arr.length; i++)              {                                                           var newarr = [random];                  console.log(newarr);                 //print name new list                  //remove name old list                  /* var arr = prompt("enter names").split(",")                  var groupnum = document.getelementbyid("input1").value;                  var newarrays =  arr.length / groupnum; */                                          }                                 } 
  /* reset */    * {    	margin: 0;    	padding: 0;    }      html,body {      height:100%;      margin:0;      font-family: 'montserrat', 'sans-serif';      color:#424242;      overflow: hidden;    }    .display {      text-align: center;      display: table;      height:100%;      margin:0 auto;    }    .wrap {      display: table-cell;      vertical-align: middle;    }    p {      font-size: 50px; /* lamers don't support viewport sizing */      font-size:20vmin;      text-align: center;      margin: 0;    }  #h2 {      float: center;      font-size: 30vmin;        background-size: contain;    }    input.text-display {      display: inline-block;      color: #5e5e5e;      font: bold 20px arial;      text-decoration: none;      text-align: center;      margin: 20px auto;      padding: 15px 20px;      background: #eff0f2;      border-radius: 4px;      border-top: 1px solid #f5f5f5;      box-shadow: inset 0 0 25px #e8e8e8, 0 1px 0 #c3c3c3, 0 2px 0 #c9c9c9, 0 2px 3px #333;      text-shadow: 0px 1px 0px #f5f5f5;    }      span.love {      display: block;      position: absolute;      bottom:10px;      width: 100%;      text-align: center;    }    span.love {      text-decoration: none;      color:#d12026;    }    .twitter-follow-button {      vertical-align: text-bottom;    }    .twitter-share-button {      vertical-align: text-bottom;    }
<div class="display">              <div class="wrap">                  <p>your random value is:</p>                  <div id="h2">null</div>                                    <input  class="text-display" type="button" onclick="yeah()" height="50px" width="50px" value="click input data">                 <!-- <input type="button" onclick="display()" value="display random"> -->                  <br>                  <input id="input1" value="enter number of groups">                  <input id="input2" value="enter number of elements per group">                  <input type="button" onclick="groups()">              </div>                        </div>

here's first fix: add new element array (like appears you're doing in loop), should use arr.push() method. you'll want declare newarr empty array before that.

i'm not entirely sure, however, you're doing intend in groups function. right looks you're choosing random name list , then, many times there names in list, assigning 1 random name new array.

what might write out list of steps want take (what call pseudo-code), turn list javascript code. can lot easier find inconsistencies in list sift through confusing code.

hope helps, let me know if have more questions!


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -