Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a script to store and maintain five athletes' information. The script will allow users to store the name and height of each athlete, and

Develop a script to store and maintain five athletes' information. The script will allow users to store the name and height of each athlete, and to find the height of an athlete. You must use the following where relevant:

  • syntax rules, data types, operators and expressions for JavaScript
  • sequence, selection and iteration constructs with the correct syntax.

Complete the following requirements using JavaScript:

  1. Declare an array to store the five athletes' name.
  2. Declare an array to store the five athletes' height in cm.
  3. Define a function with two parameters (name and height) to store an athlete's information into the arrays.
    1. In the function, create insertion algorithms to operate on the arrays and store the information in sequential order. For example, the first and the second athlete names entered will be stored in the first and second position of the first array.
    2. The function will return either 'array is full' or 'added successfully'.
  4. Define a function with one parameter (name) to remove an athlete's information from the arrays.
    1. In the function, create deletion algorithms to operate on the arrays and remove the athlete information found in the two arrays.
    2. The function will return either 'not found' or 'removed successfully'.
  5. Save the script file as TaskOne.js.
  6. Save a copy of TaskOne.js as TaskTwo.js.

Task 2: Maintain code

Refactoring is required to make the code easier to maintain.

  1. Modify the function in TaskTwo.js to remove an athlete by splitting the function into two smaller functions:

The first function must find the position of an athlete in the name array. This function has one parameter (name) to find an athlete by the name and toreturn the position of athlete found in the array, using a sequential access algorithm. If the information cannot be not found, return -1.

  1. The second function must remove an athlete's information from the arrays. This function has one parameter (name) and uses the preceding function to find the position of an athlete in the arrays. Once the position is found, use deletion algorithms to remove the information from both arrays. The function will return either 'not found' or 'removed successfully'.
  2. Save the updated TaskTwo.js script file.
  3. Ensure that your script runs and produces a correct result.
  4. Save a copy of TaskTwo.js as TaskThree.js. Task 3: Update code

Modify theTaskThree.jsscript and the provided web page file TaskThree.htmlaccording to the following requirements:

  1. TaskThree.htmlincludestwo HTML button elements. Update the required event attributes of the buttons so that Save and Find operations will be performed when a user clicks the relevant buttons.
  2. Link the TaskThree.js file to the TaskThree.html web page.
  3. Update the TaskThree.js file as follows:
    1. Change the function to find an athlete by name:
      1. Replace the sequential access algorithm to operate on the arrays with a binary search algorithm. To implement this, the array's data must be sorted. You may refer to an online example available at Array.prototype.sort() to learn about sorting data in arrays.
    2. Test your script, correct any errors that you have found and save your files.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

4. (8 points) Fill in with =, >, >=,

Answered: 1 week ago