Question

In: Computer Science

Need this in Javascript. 1. Profit Calculator A company has determined that its annual profit is...

Need this in Javascript.

1. Profit Calculator

A company has determined that its annual profit is typically 23 percent of total sales. Write a program using the file name sales_prediction.js, that displays the profit based on the user entered amount of total sales for the year. ( Program prompt the user for the projected total sales amount ). Display the profit amount formatted to two decimal places.

5 POINTS

2. Pounds to Kilogram Converter

Write a program using the file name pound_to_kg.js Prompt the user to enter the amount of lbs, and display the value in Kilograms formatted to 3 decimal points. Use full precision for the conversion value, 2.2 as an example would not provide correct conversion values.

5 POINTS

3. Purchase Calculator

A customer in a store is purchasing five items. Write a program called total_purchase.js that creates five items with literal numeric values. The prices of the items should be as follows:

item 1: $9.99

item 2: $5.99

item 3: $.99

item 4: $59.50

item 5: $.25

It then calculates and displays the subtotal of the sale, the amount of sales tax, and the total. The sales tax is 7 percent. Display the answer to two decimal places.

Solutions

Expert Solution

1) Profit Calculator:
Save the file as Sales.html
<html>
<head>
<script type="text/javascript" src="sales_prediction.js"></script>
</head>
   <body>
       <h1 id="profit">Message</h1>
   </body>
</html>

----------------------------------------------------------------------------------------------------

//sales_prediction.js
window.onload = function()
{
   //prompt for sales amount
   var annualSales = parseInt(prompt("Enter sales amount: "));
  
   // the variables are set for the equation.
   var profitPercentage = 0.23;
  
   // calculate projected profit amount
   var projectedProfit = profitPercentage * annualSales;
   //call function printProfit
   printProfit()
   //printProfit function definition
   function printProfit()
   {
           //set project profit to the element by id =profit in html file
           document.getElementById('profit').innerHTML='Total projected profits are $'+projectedProfit;
   };
}

Sample output: Open Sales.html in a chrome browser

----------------------------------------------------------------------------------------------------

2)Pounds to Kilogram Converter:


Save the below file as pounds.html

<html>
<head>
<script type="text/javascript" src="pound_to_kg.js"></script>
</head>
   <body>
       <h1 id="pounds">Message</h1>
   </body>
</html>

----------------------------------------------------------------------------------------------------

Save as pound_to_kg.js
window.onload = function()
{
   //prompt for pounds
   var numPounds = parseInt(prompt("enter the amount of lbs:"));
  
   //set pound in kgs
   var ONE_POUND = 0.453592;
  
   // calculate pounds in kgs
   var kgs = numPounds * ONE_POUND;
   //call function printProfit
   printKG()
   //printProfit function definition
   function printKG()
   {
           //set project profit to the element by id =pounds in html file
           document.getElementById('pounds').innerHTML=numPounds+' pounds=' +kgs+' kgs';
   };
}

----------------------------------------------------------------------------------------------------

Sample Output:

----------------------------------------------------------------------------------------------------
3. Purchase Calculator:
Save the file as purchase.html

<html>
<head>
<script type="text/javascript" src="total_purchase.js"></script>
</head>
   <body>
       <h1 id="sub_total"></h1>
       <h1 id="sales_tax"></h1>
       <h1 id="total_amount"></h1>
   </body>
</html>

----------------------------------------------------------------------------------------------------

Save the file as total_purchase.js

//total_purchase.js
window.onload = function()
{
       // an array of item costs
       items = [9.99,5.99,.99,59.50,.25]
       // calculate sub total amount
       var subTotal = 0
       items.forEach(function(item)
       {
       subTotal = item + subTotal;
       });
      
       display()
       //call function
       function display()
       {
          
       // the subtotal is printed.
       document.getElementById('sub_total').innerHTML='Subtotal is $'+subTotal;  
      
       // Calculatingalculating sales tax is created.
       var salesTax = subTotal * .07;
      
       // the subtotal is printed.
       document.getElementById('sales_tax').innerHTML='Sales tax is $'+salesTax.toFixed(2);
      
       // variable for total amount is created.
       var totalAmount = subTotal + salesTax;
      
       // the total cost is output to two decimal places.  
       document.getElementById('total_amount').innerHTML='The total cost is $'+totalAmount.toFixed(2);
       }
}


Sample Output:


Related Solutions

Company A has an annual income of $100 million and net profit is %20 , and...
Company A has an annual income of $100 million and net profit is %20 , and the owner wants to establish a project at a cost of $300 million. Is the project should financed from the income of Company A or financed from bank, and why?
A car insurance company has determined that the mean annual car insurance cost for a family...
A car insurance company has determined that the mean annual car insurance cost for a family in the town of Watlington is $1716. A researcher wants to perform a hypothesis test to determine whether the mean insurance cost for a family in the town of Putford is higher than this. The mean insurance cost for a random sample of 32 families in Putford was $1761. At the 10% significance level, do the data provide sufficient evidence to conclude that the...
A car insurance company has determined that the mean annual car insurance cost for a family...
A car insurance company has determined that the mean annual car insurance cost for a family in the town of Watlington is $1716. A researcher wants to perform a hypothesis test to determine whether the mean insurance cost for a family in the town of Putford is higher than this. The mean insurance cost for a random sample of 32 families in Putford was $1761. At the 10% significance level, do the data provide sufficient evidence to conclude that the...
A relatively new company, Wine To End Whining, Inc., has determined they need to engage in...
A relatively new company, Wine To End Whining, Inc., has determined they need to engage in a budgeting process as part of their new strategic plan. The Company has asked you to provide the following items for the months of January, February, and March of 2017: A) a Purchases Budget; B) a Cash Budget; C) a Budgeted Income Statement; and D) a Budgeted Balance Sheet. They have provided you with the planning document below and also, with their December 31,...
A relatively new company, Wine To End Whining, Inc., has determined they need to engage in...
A relatively new company, Wine To End Whining, Inc., has determined they need to engage in a budgeting process as part of their new strategic plan. The Company has asked you to provide the following items for the months of January, February, and March of 2017: A) a Purchases Budget; B) a Cash Budget; C) a Budgeted Income Statement; and D) a Budgeted Balance Sheet. They have provided you with the planning document below and also, with their December 31,...
A relatively new company, Wine To End Whining, Inc., has determined they need to engage in...
A relatively new company, Wine To End Whining, Inc., has determined they need to engage in a budgeting process as part of their new strategic plan. The Company has asked you to provide the following items for the months of January, February, and March of 2017: A) a Purchases Budget; B) a Cash Budget; C) a Budgeted Income Statement; and D) a Budgeted Balance Sheet. They have provided you with the planning document below and also, with their December 31,...
"The FIN340 Company has a net profit margin of 8.75% on annual sales of $86,500,000 and...
"The FIN340 Company has a net profit margin of 8.75% on annual sales of $86,500,000 and the firm has 980,000 shares outstanding. If the firm's P/E ratio is 7.2, how much is the stock currently selling for?"
1. A company has just paid its annual dividend of $3.95 yesterday, and it is unlikely...
1. A company has just paid its annual dividend of $3.95 yesterday, and it is unlikely to change the amount paid out in future years. If the required rate of return is 18 percent p.a., what is the share worth today? (to the nearest cent; don’t include $ sign) 2. A company has just paid its first dividend of $3.78. Next year's dividend is forecast to grow by 5 percent, followed by another 5 per cent growth in year two....
As a result of its annual inventory count, Flounder Corp. determined its ending inventory at cost...
As a result of its annual inventory count, Flounder Corp. determined its ending inventory at cost and at lower of cost and net realizable value at December 31, 2019, and December 31, 2020. December 31, 2019, was Flounder’s first year end. This information is as follows: Cost Lower of Cost and NRV Dec. 31, 2019 $ 321,700 $283,350 Dec. 31, 2020 386,000 351,250 A. Prepare the journal entries required at December 31, 2019 and 2020, assuming that the inventory is...
Bird's Eye Treehouses, Inc., a Kentucky company, has determined that a majority of its customers are...
Bird's Eye Treehouses, Inc., a Kentucky company, has determined that a majority of its customers are located in the Pennsylvania area. It therefore is considering using a lockbox system offered by a bank located in Pittsburgh. The bank has estimated that use of the system will reduce collection time by 2.5 days. Assume 365 days a year.      Average number of payments per day 840   Average value of payment $ 790   Variable lockbox fee (per transaction) $ 0.20   Annual interest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT