-
-
Save vettukal/9502144141487853aadad0a0b5778b92 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/kebule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var PHONE_PRICE = 31; | |
var SPENDING_THRESHOLD = 23; | |
var bank_balance = 309; | |
var phone_accesory = 5; | |
var tax_rate = 12.5; | |
var total_amount = 0; | |
while(PHONE_PRICE < bank_balance){ | |
var gross_total = 0; | |
if(phone_accesory < SPENDING_THRESHOLD){ | |
SPENDING_THRESHOLD -= phone_accesory; | |
gross_total += phone_accesory; | |
} | |
gross_total += PHONE_PRICE; | |
total_amount += add_tax(gross_total); | |
bank_balance -= add_tax(gross_total); | |
} | |
console.log(pretty_print(total_amount)); | |
function pretty_print(total_amount){ | |
return '$'+total_amount.toFixed(2); | |
} | |
function add_tax(gross_total){ | |
return gross_total * (1+tax_rate/100); | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
var PHONE_PRICE = 31; | |
var SPENDING_THRESHOLD = 23; | |
var bank_balance = 309; | |
var phone_accesory = 5; | |
var tax_rate = 12.5; | |
var total_amount = 0; | |
while(PHONE_PRICE < bank_balance){ | |
var gross_total = 0; | |
if(phone_accesory < SPENDING_THRESHOLD){ | |
SPENDING_THRESHOLD -= phone_accesory; | |
gross_total += phone_accesory; | |
} | |
gross_total += PHONE_PRICE; | |
total_amount += add_tax(gross_total); | |
bank_balance -= add_tax(gross_total); | |
} | |
console.log(pretty_print(total_amount)); | |
function pretty_print(total_amount){ | |
return '$'+total_amount.toFixed(2); | |
} | |
function add_tax(gross_total){ | |
return gross_total * (1+tax_rate/100); | |
}</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PHONE_PRICE = 31; | |
var SPENDING_THRESHOLD = 23; | |
var bank_balance = 309; | |
var phone_accesory = 5; | |
var tax_rate = 12.5; | |
var total_amount = 0; | |
while(PHONE_PRICE < bank_balance){ | |
var gross_total = 0; | |
if(phone_accesory < SPENDING_THRESHOLD){ | |
SPENDING_THRESHOLD -= phone_accesory; | |
gross_total += phone_accesory; | |
} | |
gross_total += PHONE_PRICE; | |
total_amount += add_tax(gross_total); | |
bank_balance -= add_tax(gross_total); | |
} | |
console.log(pretty_print(total_amount)); | |
function pretty_print(total_amount){ | |
return '$'+total_amount.toFixed(2); | |
} | |
function add_tax(gross_total){ | |
return gross_total * (1+tax_rate/100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment