Assignment2
by Tori Hoelscher
HTML
<div id="operations1"></div><br>
<div id="operations2"></div><br>
<div id="find"></div><br>
<div id="find-option"></div><br>
<div id="form-array">
<form>
Index:<br>
<input type="text" name="index" id="index" value="3"><br>
Number:<br>
<input type="text" name="number" id="number" value="0"><br><br>
</form>
<input type="submit" id="click" value="Update Array"><br><br>
</div>
<div id="updated-array"></div>
JavaScript
function shuffle(o) { //v1.0
for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
// populate the variable "array" with 9 different
// random numbers
function randomlyInitializeArray(min, max) {
var start = min;
var randomMax = randomIntFromInterval(min, max)
var myArray = [];
for (var i = 0; start <= randomMax; myArray[i++] = start++);
myArray = shuffle(myArray);
console.log("Min: "+min);
console.log("Max: "+max);
console.log("random Max: "+randomMax)
console.log(myArray)
}
randomlyInitializeArray(1,100);
Array.insertintoArray(myArray, 2, 'c');
alert(myArray);