getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
179.37k stars 33.48k forks source link

Time to Practice! How many phones you can afford. [YDKJS: Up & Going. Chapter 1: Into Programming] #595

Closed ghost closed 8 years ago

ghost commented 8 years ago

function affordItems(mob_amt, acces_amt, bank_amt, tax_rate){

var i = 0, amtFinal = 0;
amtFinal = (mob_amt + acces_amt) + (mob_amt * tax_rate);
var totTax = 0;

for(bank_amt; bank_amt > mob_amt; bank_amt -= mob_amt){    
   totTax += amtFinal - mob_amt;
   i++;
}

if (i > 0) {
   console.log('You can afford: '+ i + ' item(-s) and accessories.\nMoney left: $' + bank_amt.toFixed(2) + '.\nTaxes paid: $' + totTax.toFixed(2));
}
else {
   console.log('No sufficient bank amount!');
};

}

// get 'bank_amt' by 'prompt()' var bank_amt = prompt(), // let's enter, f.e.: 1500 tax_rate = 0.13;

affordItems(199.99, 2.99, bank_amt, tax_rate);

You can afford: 7 item(-s) and accessories. Money left: $100.07. Taxes paid: $202.92

geekodour commented 8 years ago

What's the issue here?

getify commented 8 years ago

Closing for now since there's no response from OP. I don't understand this issue either.