Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please solve this JavaScript problem. Send me the codes HTML and JavaScript codes along with comments so that I can understand and learn. Thank you.
please solve this JavaScript problem. Send me the codes HTML and JavaScript codes along with comments so that I can understand and learn. Thank you.
You'll use your new skills in JavaScript to do data processing with functions, objects and arrays. Create an HTML file called A2.html. Create a script called A2.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. 1. num_items : will store the number of loops you'll perform and it's value must be 20 . 2. your_name : will store your given first name. 3. original : an empty array you will fill in Part B 4. upper : an empty array you will fill in Part C 5. matches : an empty object, you will fill in Part D 6. 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 1. original is an array of objects that contains a number of entries equal to num_items. 2. 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. 3. 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(21). The second item would have a sum of 4(2+2) and a product of 4(22). ou must create a function called toUpperTimesthree (input). 1. 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. 2. 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. 3. Your code must loop through the input array and generate a new array that is formatted similarly, but with different values. 4. 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. 5. 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. art D: Matches Object ou must create a function called f indMatches (0,u). This function finds atching 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: 'Paulo', sum: 6, product: 5} up: \{name: 'PAULO', sum: 6, product: 3 , div: 0.5}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