Activity 12: Array What is an

Activity 12: ArrayWhat is an Array?An array is a special variable, which can hold more than one valueat a time.If you have a list of items (a list of car names, for example),storing the cars in single variables could look like this:var car1 = “Saab”; var car2 =”Volvo”;var car3 = “BMW”;However, what if you want to loop through the cars and find aspecific one? And what if you had not 3 cars, but 300?The solution is an array!An array can hold many values under a single name, and you canaccess the values by referring to an index number.Syntax: var array-name = [item1, item2,…];    Example:   var cars = [“Saab”, “Volvo”, “BMW”];Arrays are allocated using the new keyword.Array indexes start at 0 and extend to the size of the array minus1. To assign a value to an element of an array open and closebrackets are used.The size of an array can be increased dynamically by assigning avalue to an element pass the end of the array. Array can be createdthat initially has no elements at all. In addition, they are not ofa fixed size but can grow dynamically.The array, pictures, initially has no elements. After “Mona Lisa”has been assigned the array has 36 elements. The unassignedelements are set to Undefined.The length property of arrays returns the number of elements in thearray.Tasks 1Create an array of 5 animals. Use for loop to list values in thearray.1. Go through the lecture slides and understand arrays andmultidimensional arrays.2. Define a function max() that takes two numbers as arguments andreturns the largest of them. Use the if-then-else constructavailable in Javascript.


For tasks 1, the array and the required function has been codedbelow, Some comment lines are also used in the code to state whatthe code is doing. In case of any query, you can mention it in thecomment section. HAPPY LEARNING!!

For getting the output, you need to put the javascript codeunder html tags and save it with the extension .html and open itwith any browser.


      <html>            <script>                var animals = new Array("Cat","Dog","Human","Elephant","Horse");   // created the array of animals dynamically using new keyword                var listed_animals = "";                for (var i = 0; i < animals.length; i++) {                   listed_animals += animals[i] + " ";      // accessing the values of array by for loop and concatenating in a single string separated by space                }                document.write("<b>Listed animals are: </b>");                document.write(listed_animals);               // written the listed animals on the page                function Max(x,y) {                   // function definition                  if (x>y){                           // checking if x is greater than y                        return x;                        }                  else if (x<y){                        // if x is less than y                        return y;                        }                  else{                                  // else both are equal                        return "Both are equal";                        }                }                                document.write("<p>The biggest in 12 and -34 is"+Max(12,-34)+"</p>");        </script> </html>


"Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!"
Calculate the price
Make an order in advance and get the best price
Pages (550 words)
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Customer reviews in total
Current satisfaction rate
3 pages
Average paper length
Customers referred by a friend
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat

Sometimes it is hard to do all the work on your own

Let us help you get a good grade on your paper. Get professional help and free up your time for more important courses. Let us handle your;

  • Dissertations and Thesis
  • Essays
  • All Assignments

  • Research papers
  • Terms Papers
  • Online Classes