Assignment-2
COP3530
by Ron Eaglin
HTML
<table style="width: 850px; height: 154px;" border="0">
<tbody>
<tr>
<td>Enter Array Size: <input style="width: 50px;" type="textbox" id="size" value="100" />
<input type="button" value="Create Array" onClick="createArray();" /></td>
</tr>
<tr>
<td>Enter Location: <input style="width: 50px;" type="textbox" id="loc" value="5" />
Enter Value to Insert: <input style="width: 50px;" type="textbox" id="val" value="99" /><input type="button" value="Insert Into Array" onClick="insertInArray();" /></td>
</tr>
<tr>
<td>Enter Value to Find: <input style="width: 50px;" type="textbox" id="find" value="20" /><input type="button" value="Search Array" onClick="searchArray();" /></td>
</tr>
</tbody>
</table>
<div id="output">
</div>
JavaScript
var array = [];
var dis = "";
function createArray() {
clearDisplay();
size = parseInt(document.getElementById("size").value);
for (var i = 0; i < size; i++) {
array[i] = Math.floor(Math.random() * size + 1);
}
displayArray();
}
function clearDisplay() {
dis = "";
document.getElementById("output").innerHTML = "";
}
function displayArray() {
for (var i = 0; i < array.length - 1; i++) {
dis += i + ' : ' + array[i] + "<br/>";
}
document.getElementById("output").innerHTML = dis;
}
/*function insertInArray(array, val, loc) {
clearDisplay();
var l = parseInt(document.getElementById("loc").value);
var v = parseInt(document.getElementById("val").value);
}*/