Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. /* The user enters a cost of an item and then the amount of
  2. money given. The program will figure out the change and the number of quarters, dimes, nickels, pennies needed for the change.*/
  3.  
  4.  
  5. var cost = prompt('please enter total cost of the item without tax');
  6. cost = parseFloat(cost);
  7.  
  8. var moneyGiven = prompt('please enter the amount of money given');
  9. moneyGiven = parseFloat(moneyGiven);
  10.  
  11. var tax = 0.15;
  12. tax = (cost*tax);
  13.  
  14. var quarter = 0;
  15. var dime = 0;
  16. var nickel = 0;
  17. var penny = 0;
  18.  
  19. var q = 0.25;
  20. var d = 0.10;
  21. var n = 0.05;
  22. var p= 0.01;
  23. var change = (moneyGiven - (cost + tax));
  24. console.log(change);
  25.  
  26. while(change > 0){
  27.  
  28. if (change >= q){
  29. change - q;
  30. quarter++;
  31. }
  32.  
  33. else if (change >= d){
  34. change - d;
  35. dime++;
  36. }
  37.  
  38. else if (change >= n){
  39. change - n;
  40. nickel++;
  41. }
  42.  
  43. else if ( change >= p) {
  44. change - p;
  45. penny++;
  46. }
  47.  
  48. };//while loop
  49.  
  50. console.log(quarter);
  51. console.log(dime);
  52. console.log(nickel);
  53. console.log(penny);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement