Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The user enters a cost of an item and then the amount of
- money given. The program will figure out the change and the number of quarters, dimes, nickels, pennies needed for the change.*/
- var cost = prompt('please enter total cost of the item without tax');
- cost = parseFloat(cost);
- var moneyGiven = prompt('please enter the amount of money given');
- moneyGiven = parseFloat(moneyGiven);
- var tax = 0.15;
- tax = (cost*tax);
- var quarter = 0;
- var dime = 0;
- var nickel = 0;
- var penny = 0;
- var q = 0.25;
- var d = 0.10;
- var n = 0.05;
- var p= 0.01;
- var change = (moneyGiven - (cost + tax));
- console.log(change);
- while(change > 0){
- if (change >= q){
- change - q;
- quarter++;
- }
- else if (change >= d){
- change - d;
- dime++;
- }
- else if (change >= n){
- change - n;
- nickel++;
- }
- else if ( change >= p) {
- change - p;
- penny++;
- }
- };//while loop
- console.log(quarter);
- console.log(dime);
- console.log(nickel);
- console.log(penny);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement