Slipmaks

q

May 14th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var Cash_Balance = prompt ('Spend money value','');
  4. const Phone_Price = 150;
  5. const Accessories = 9.99;
  6. const Price_Tax = 0.08;
  7.  
  8.  
  9. function buyPhone (){
  10.    
  11.     var amount = Phone_Price + Accessories;
  12.     var price = 0;
  13.     var i = 0;
  14.     while (true) {
  15.     price = price + amount;
  16.     i++;
  17.     if ( price >= Cash_Balance) {
  18.         price = price - amount;
  19.         --i;
  20.         price = price + price * Price_Tax;
  21.         break;
  22.     }
  23. }
  24. alert('$'+price.toFixed(2));
  25. if ( price >= Cash_Balance ) {
  26.     alert("you don't have money for that transaction");
  27. } else {
  28.     alert('conzratz you got '+i+' phone(s), full price is $'+price.toFixed(2));
  29. }
  30. }
  31. buyPhone();
Advertisement
Add Comment
Please, Sign In to add comment