December 11, 2019

JavaScript Arrays

 

This question tests your knowledge of arrays.

  • How to create an array
  • How to write data to an array
  • How to access the data stored in an array

You may assume for the purposes of both parts of this question that all data entered is valid and at no point will the user cancel.

Q9.
i)
A program is to be written that uses an array to store the names and corresponding heights of mountains. Input is made via dialogue boxes and prompting messages that will take the form of
Enter name of mountain

This should be followed immediately by
Enter height of mountain

The user will be limited to the input of data for five mountains, no more, no less. Once completed your program should output, via a single dialogue box, a list of all five mountain names. No sorting is required. An example output is:

Alert box containing output of list of five mountain names

ii)
Your program is to be extended, so that once the user clicks OK on the alert box in part (i), another dialogue box is to be displayed with the name of the highest mountain. You are to write and call a function getHighestName(), which takes as its argument an array of names and heights as constructed in part(i). This function will return a string, which represents the name of the highest mountain in the array.

Link to answer.

 

Next page » Objects

Previous page « Password Problem

 

 

 

 

 

 

 

Up to top of page