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 ResultsExplanation / 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>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.