<html>
<head>
<h2>
Juan Alban Franco <br>
Assignment 2
</h2>
</head>
<body>
<!-
I will need 4 buttons:
- Create Array
1. will create the array using input textbox whose value will dictate array size.
2. Input textbox:
- Insert into Array
- Search Array
->
<script>
//
var Int_Array= new Array; //global array that will contain integers.
var String_Holder; // string that will contain the integers and concat with html code
function Create_Array(size)
{
// always clear output
document.getElementById("d").innerHTML = "";
//always clear array
Int_Array.length = 0
// dump sting_holder variable
String_Holder = "";
for (var i = 0; i < size; i++)
{
var x = Math.random();
var value = Math.floor((x * 99) + 1);
Int_Array[i] = value;
String_Holder += "Position: " + i + " Value: " + Int_Array[i] + "<br>"
}
document.getElementById("d").innerHTML = String_Holder;
}
function Add_To_Array(pos, val)
{
if(pos > Int_Array.length)
{
document.getElementById("i").innerHTML = "Please select a position between 1 and "+ Int_Array.length;
document.getElementById("iO").innerHTML = "";
return;
}
var counter = 0;
var int_holder;
var l = Int_Array.length;
counter ++;
//clear out display
document.getElementById("i").innerHTML = '';
counter ++;
//places the value from text box into the end of the array ( essentially deleting the last item and replacing it with val)
Int_Array[l-1] = val
counter ++;
//document.getElementById("i").innerHTML = Int_Array;
while (l>pos)// itereate through array from the last elemnt up to the position of the inserted value.
{
int_holder=Int_Array[l-1]; //picks up the last number into a carry spot
counter++;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.