Assignment 2

by Juan Alban Franco

HTML

<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++;
     ...