for example, When i try to type the example from YDKJS into chrome, an error that says that “identifier TAX_RATE has already been identified” How do i get around this?
const TAX_RATE = 0.08125;
const PHONE_PRICE = 600;
const ACCESSORY_PRICE = 40;
const SPENDING_THRESHOLD = 200;
var amount = 0;
var bank_balance = 30000;
function calcTax(amount){return amount * TAX_RATE};
function formatAmount(amount){return $ + amount.toFixed(2);}
while (amount <= bank_balance){amount = amount + PHONE_PRICE; if (amount <= SPENDING_THRESHOLD) {amount = amount + ACCESSORY_PRICE}}
amount = amount + calcTax(amount);
console.log("Your Purchase:" + formatAmount(amount));
if (amount > bank_balance) {console.log("Sorry, you're broke as hell");}
I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.
I think it’s because you’re running the same code twice. So when you run the same code again, it tries to assign something to TAX_RATE, but then you’re trying to redeclare a constant, which is not allowed.
@Tyrantt47 Here’s simple answer I have. const TAX_RATE = 0.08125; is entered the first time you run the code. Later when run the code again, without refreshing, you are really attemting to overide a constant. This not allowed. Refreshing wipes the slate clean so there are no conflicts.
You should also get the same error if you use varwhen you declare a variable.
Another way to get around this, besides refreshing the page, is to ommit const and var.