Question
In this assignment, you are to calculate several answers about an array, and output the results using innerHTML Use this array as the input of
In this assignment, you are to calculate several answers about an array, and output the results using "innerHTML"
Use this array as the input of this assignment:
let prices = [ 6.67, 1.38 ,5.77, 6.47, 4.97, 6.40, 7.85, 4.61, 0.81, 8.85, 9.35, 12.87 ] ;
Your output will include:
- The number of elements (length) in the array.
- The index number of the first element in the array.
- The content of the first element in the array.
- The index number of the last element in the array.
- The content of the last element in the array.
- The sum of all the elements in the array.
Your program must use "innerHTML" to write the output into your HTML file. There is a place for each answer in the supplied HTML. You do not need to change any of the supplied HTML.
For example, for output 1 (above) you are to get the number of items in the array (using the "length" property) and then use the "innerHTML" property to write the answer into the HTML page into this section of the HTML:
Count of array elements
Use this HTML for your HTML file. You should save it to "public_html/csci212/week4/index.html"
Arrays and Loops Assignment Arrays and Loops Assignment
Count of array elements
The index number of the first element in the array
The first element in the array
The index number of the last element in the array
The last element in the array
The sum of all elements in the array
JavaScript requirements
Put your JavaScript in "public_html/csci212/week4/js/scripts.js"
Your Javascript should include a comment block at the beginning to document the file.
Your Javascript should include enough comments within the code to document what the code is doing. In fact, you can write comments before you start to code as just pseudocode statements to document the steps that you need to do to complete the assignment.
Your program should wait until the page is loaded before it runs by using "window.onload."
Your program should be contained within a function to prevent any variables from leaking out into global scope.
The basic structure of your code should look like this:
// Wait until the page loads. window.onload = function() { outputAnswers(); }; // Take provided array as input, calculate several answers, and output to provided HTML. function outputAnswers() { let prices = [ 6.67, 1.38 ,5.77, 6.47, 4.97, 6.40, 7.85, 4.61, 0.81, 8.85, 9.35, 12.87 ] ; // the rest of your program... }
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