Question
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:
- Declare an array to store the five athletes' name.
- Declare an array to store the five athletes' height in cm.
- Define a function with two parameters (name and height) to store an athlete's information into the arrays.
- 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.
- The function will return either 'array is full' or 'added successfully'.
- Define a function with one parameter (name) to remove an athlete's information from the arrays.
- In the function, create deletion algorithms to operate on the arrays and remove the athlete information found in the two arrays.
- The function will return either 'not found' or 'removed successfully'.
- Save the script file as TaskOne.js.
- Save a copy of TaskOne.js as TaskTwo.js.
Task 2: Maintain code
Refactoring is required to make the code easier to maintain.
- 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.
- 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'.
- Save the updated TaskTwo.js script file.
- Ensure that your script runs and produces a correct result.
- 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:
- 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.
- Link the TaskThree.js file to the TaskThree.html web page.
- Update the TaskThree.js file as follows:
- Change the function to find an athlete by name:
- 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.
- Test your script, correct any errors that you have found and save your files.
- Change the function to find an athlete by name:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started