Really getting frustrated with this homework assignment.
Screwed up my entire weekend and it is due tomorrow.
I have this script starting over so that another food bill could be tried again.
The problem has been that to opt out of the script and discontinue the viewer must type -999
Code:
main();
function main()
{
var bill = purchasePrice(); //price on the food bill
caculateTotalBill(bill); //Tip plus food bill
}
function purchasePrice()
{
pp = parseFloat(prompt("Input how much your meal purchase is. To exit type -999", ""));
var MINPRICE = .10;
var MAXPRICE = 1000;
//Validate the inputted pp
if (pp = -999)
{exit}
while((isNaN(pp)) || (pp < MINPRICE) || (pp > MAXPRICE))
{
alert("Invalid purchase price inputted. Please reenter.");
pp = parseFloat(prompt("Input how much your meal purchase is", ""));
}
return pp;
}
function caculateTotalBill(bill)
{
//MODULE caculateTotalBill()
var TIP = 0.15; //Going rate for tip
var TAX = 0.07; //tax
var theTip = bill * TIP;
var theTax = bill * TAX;
var totalBill = bill + theTip + theTax;
outputInfo(bill, theTip, theTax, totalBill);
}
function outputInfo (bill, theTip, theTax, totalBill)
{
alert("Meal purchase price: " + "\t\t" + bill.toFixed(2) + "\n" +
"Tip: " + "\t\t\t\t\t\t" + theTip.toFixed(2) + "\n" +
"Tax: " + "\t\t\t\t\t" + theTax.toFixed(2) + "\n" +
"Your total bill will be: " + "\t\t" + totalBill.toFixed(2));
start(bill);
}
function start(bill)
{
while (bill != -999)
{
main();
}
alert("Thanks! See ya!");
}
Bookmarks