Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You'll use your new skills in JavaScript to do data processing with functions, objects and arrays. Create an HTML file called A4.html. Create a script

You'll use your new skills in JavaScript to do data processing with functions, objects and arrays. Create an HTML file called A4.html. Create a script called A4.js. Load that script in the

of your site, so that it runs when the page is loaded. Part A : Variable declarations You'll need six variables, all of which must be declared at the start of the script. num_items : will store the number of loops you'll perform and it's value must be 20. your_name : will store your given first name. original : an empty array you will fill in Part B upper : an empty array you will fill in Part C matches : an empty object, you will fill in Part D starting_number : you must use a prompt to acquire this number from the user. You do not need to worry about validating the input. Assume it's a valid numeric value being typed. Part B : Original Array You must use a for loop to fill in the original array. This requires you to keep count of the interactions of the loop. So in the first iteration, the count is 1. Then 2. etc original is an array of objects that contains a number of entries equal to num_items. Each item in the array is an object with three keys. name : will store your name sum : a number that is the sum of the starting_number and the count in the loop. product : a number that is the product (multiplication) of the starting_number and the count in the loop. This means that if the user enters the number 2 then the first value of the loop would have a sum of 3 (2+1) and a product of 2 (2*1). The second item would have a sum of 4 (2+2) and a product of 4 (2*2). Part C : Upper Array You must create a function called toUpperTimesThree(input). This function must accept a parameter called input which you will pass in your original array you created. You cannot modify or access the original variable from inside the function directly. You must use the parameters. This function returns an array that is formatted the same was the input. It has the same number of indices and each value in the array is an object. Your code must loop through the input array and generate a new array that is formatted similarly, but with different values. Each object in the array has four(4) keys: name : the name from the input, however converted to uppercase letters sum : the sum from the input but multiple by three(3) product : the product from the input but multiple by three(3) div : the value when the product from the input is divided by the sum from the input. This array is returned by this function and stored in the upper variable declared at the start. Your function cannot modify the upper variable directly from inside this function. Part D : Matches Object You must create a function called findMatches(o, u). This function finds matching items between the two arrays and returns an object with those matches. This function accepts two parameters called o and u which you will pass in your original array and the upper array you created. You cannot modify or access the original or upper variables from inside the function directly. You must use the parameters. This function returns an object with two keys: sum_matches : this is an array of objects. Each object with two keys called or and up. product_matches : this is an array of objects. Each object with two keys called or and up. Your code must loop through both the o and u arrays and find any time those two arrays have a matching sum value. When one of those matches is found, a new item is added to sum_matches. That item is an object with two keys. The or key contains the object found in the o parameter. The up key contains the object found in the u parameter. Now obviously these represent the original and upper values, but I've chosen different names to avoid confusion. Everything described above is true for the product matches. These values are returned by this function and stored in the matches variable you declared at the start of the code. To elaborate on this, you're returning a single object at the end of all this. It has two keys which contain a collection of matches. The sum matches, contain all the times when sums of the original and upper matched. Example: For if the starting of value was 1, the first time the two sums line up is with the sum of 6. So the first index (0) in the sum_matches array is an object with two values or and up, each of which has the value of the specific original and upper values that generated the match. sum_matches[0] = { or: {name: 'jackie', sum: 6, product: 5} up: {name: 'JACKIE', sum: 6, product: 3, div: 0.5} } Part E : Output In order to test your code, you must output your three variables at the end of our code. If you have other console items, comment them out before submitting. To avoid confusion, these must be the last three lines of your code. Please copy/paste them. No console output should happen anywhere else. console.log('Original', original); console.log('Upper', upper); console.log('Matches', matches);

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

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

What general conclusions can be drawn from research on experience?

Answered: 1 week ago