Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that lists 5 sale amounts in an array then loop through the sal

ID: 3564569 • Letter: W

Question

Write a function that lists 5 sale amounts in an array then loop through the sale amounts adding the individual sale amounts in order to determine the total sales amount. Display this total sales amount in a alert message. (Hint, use Listing 3.5.6 on page 50 as reference).

Write a function that lists 5 sale amounts in an array then loop through the sale amounts adding the individual sale amounts in order to determine the total sales amount. Display this total sales amount in a alert message. (Hint, use Listing 3.5.6 on page 50 as reference). Listing 3.5.6 A function That will Take the Family Array, Loop, and Alert the Results

Explanation / Answer

=======================================================================

totalsales.html

======================================================================

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" charset="UTF-8">
<title>Total Sales</title>
<script type="text/javascript">

function salesAmount(){
  
   /* Sales amount array*/
   var sales = [256,343,242,243,345,199];
  
   /* Declare total sales and initialize to 0 */
   var totalSales = 0;
   var noOfSales = sales.length;
  
   /* Loop through sales array */
   for(var i=0; i<noOfSales; i++){
       var amount = sales[i];
       totalSales = totalSales+amount; /* Add amount to total*/
   }
  
   alert("Total Sales: "+totalSales);
  
}


</script>
</head>
<body>
<input type="button" value="Click Here" />
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote