Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. The number of elements (length) in the array.
  2. The index number of the first element in the array.
  3. The content of the first element in the array.
  4. The index number of the last element in the array.
  5. The content of the last element in the array.
  6. 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

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

4. How is culture a contested site?

Answered: 1 week ago