|
| 1 | +// Defining constant variables. |
| 2 | +const TAX_RATE = 0.08; |
| 3 | +const PHONE_PRICE = 99.99; |
| 4 | +const ACCESSORY_PRICE = 09.99; |
| 5 | +const SPENDING_LIMIT = Number.parseInt(prompt('What is your limit?', '200')); |
| 6 | + |
| 7 | +//Defining variables. |
| 8 | +var initialBalance = prompt('What Your Balance?', '9000'); |
| 9 | +var accountBalance = Number.parseInt(initialBalance); |
| 10 | + |
| 11 | +var tempSalesAmount; |
| 12 | + |
| 13 | +//funtion definitions. |
| 14 | + |
| 15 | +/* function calculateFormatAmount(){ |
| 16 | +var amountAfterTax = Number.parseInt(tempSalesAmount + (tempSalesAmount * TAX_RATE)); |
| 17 | + return '$' + amountAfterTax; |
| 18 | +}*/ |
| 19 | +function calculateAfterTax() { |
| 20 | + var amountAfterTax = Number.parseInt(tempSalesAmount + (tempSalesAmount * TAX_RATE)); |
| 21 | + return '$' + amountAfterTax.toFixed(2); |
| 22 | +} |
| 23 | + |
| 24 | +function formatAmount(amount) { |
| 25 | + return '$' + amount.toFixed(2); |
| 26 | +} |
| 27 | + |
| 28 | +// Logic and conditionals. |
| 29 | +while (accountBalance > SPENDING_LIMIT) { |
| 30 | + console.log('Welcome to AT&T, You say you only want to spend ' + formatAmount(SPENDING_LIMIT) + '?'); |
| 31 | + tempSalesAmount = PHONE_PRICE; |
| 32 | + console.log('Well Lookey here, This beautiful Samsung is only $500.. This zte is ' + PHONE_PRICE + ' Thats more within your budget, Isnt it.') |
| 33 | + if (accountBalance > tempSalesAmount) { |
| 34 | + tempSalesAmount = tempSalesAmount + PHONE_PRICE + ACCESSORY_PRICE; |
| 35 | + console.log('after adding the accesory to your order, your current balance is ' + formatAmount(tempSalesAmount)); |
| 36 | + accountBalance = accountBalance - tempSalesAmount; |
| 37 | + console.log("After Taxes that comes to " + calculateAfterTax(tempSalesAmount)); |
| 38 | + |
| 39 | + } |
| 40 | + else if (accountBalance < SPENDING_LIMIT) |
| 41 | + console.log('Im sorry the but your card has been declined'); |
| 42 | + console.log('currentBalance is ' + formatAmount(accountBalance)); |
| 43 | + |
| 44 | +} |
| 45 | + |
| 46 | + console.log("Thank you for shopping with us, come back soon, ya here!") |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +/* Writing function to optimize code. |
| 54 | +function buyProduct(){ |
| 55 | + while (accountBalance !> SPENDING_LIMIT){ |
| 56 | + */ |
0 commit comments