Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Assignment 6 -Intro to programming javascript

MIT 153 – Assignment #6 This assignment requires you to use a separate data file names Asgn6Data.js. This is an external JavaScript file can be “imported” into your Web page by putting the following tags in the “head” section: <script type=”text/javascript” src=”Asgn6Data.js”></script> This file declares a number of arrays and fills them with data. Open the file in a text editor and inspect the data. All of these variables and values will now be available inside your page. (DO NOT try to declare these variables in your code – once you have inserted the above tags these variables are already a part of your page.) Write a program that will use an array to accumulate the total sales by department number as well as an overall total. A sample output is shown below. Note: the department numbers range from one to ten. Use an array of size ten to hold the totals and display the names of the departments from the departNames array provided in the file. Sales by Department
Department Total
Housewares 26.13
Kitchen 12.66
Living Room 15.63
Patio 8.95
Garden 17.25
Hardware 14.73
Sporting Goods 20.61
Automotive 18.36
Tools 204.67
Chemicals 66.43
Total sales: 405.42 Answer
</span>
<pre class="wp-block-syntaxhighlighter-code"><span style="color: #000000; font-family: verdana, geneva, sans-serif;"><!DOCTYPE html&gt;
<head&gt;
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt;
<script type="text/javascript" src="Asgn6Data.js"&gt;</script&gt;
<title&gt;</title&gt;
</head&gt;
<body&gt;
<script type="text/javascript" &gt;

var total = new Array(10);
var salesTotal=0;
var BR="<br/&gt;";
for (var idx = 1; idx <= 10; ++idx) {
	total[idx] = 0;
}
for (var x = 0; x <40; ++x) {
var itm=itemDept[x];
total[itm] += itemQnty[x]*itemPrc[x];
}
document.write("<h2&gt;Sales by Department</h2&gt;");
document.write("<table width='200' border='1' &gt;<tr&gt;<td&gt;<strong&gt;Department</strong&gt;<td width='70' border='1'&gt;<strong&gt;Total</strong&gt;</td&gt;</td&gt;</tr&gt;<table&gt;");
for (var dx = 0; dx <10; ++dx) {
document.write("<table width='200' border='1' &gt;<tr&gt;<td&gt;"+departNames[dx] +"  "+ "<td width='70' border='1'&gt;"+(total[dx+1]).toFixed(2)+"</td&gt;</td&gt;</tr&gt;<table&gt;");
	salesTotal += total[dx+1];
}
document.write("<h4&gt;"+BR+"Total Sales:"+"  " +salesTotal +"</h4&gt;");
</script&gt;
</body&gt;
</html&gt;






</span></pre>

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!