Hey there! I'm currently working on a school project where I need to create random groups of names from a given list. The size and number of groups will depend on the user's input. I've managed to write code that randomly selects an element from the array, but now I need some assistance with grouping the names together. Here's what I have so far, but it's not fully functional. Any help would be greatly appreciated. Thank you!
function generateRandomName()
{
var names = prompt("Enter your names").split(",")
console.log(names);
var random = names[Math.floor(Math.random() * names.length)];
document.getElementById("h2").innerHTML = random;
}
function groupNames()
{
var names = prompt("Enter your names").split(",");
var random = names[Math.floor(Math.random() * names.length)];
var numElements = document.getElementById("input2").value;
for (i=0;i <= names.length; i++)
{
var newNameGroup = [random];
console.log(newNameGroup);
//print name to a new list
//remove name from old list
/* var arr = prompt("Enter your 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; /* For lamers who 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 a {
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="generateRandomName()" height="50px" width="50px" value="click to 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="groupNames()">
</div>
</div>