In: Computer Science
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.
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:
