Skip to content

Instantly share code, notes, and snippets.

@vettukal
Forked from anonymous/index.html
Created October 2, 2016 18:24
Show Gist options
  • Save vettukal/9502144141487853aadad0a0b5778b92 to your computer and use it in GitHub Desktop.
Save vettukal/9502144141487853aadad0a0b5778b92 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/kebule
<!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>
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