Whenever i try to type in javascript in the developer tools in chrome, it constantly says that "identifier has already been delcared" how do i fix this?

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;
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");}

@Tyrantt47 refresh the page then enter your code again.

awesome, thanks for that! any idea why i get this when i excute the code?: Your Purchase:function (e,t){return new oe.fn.init(e,t)}33086.25

The dollar sign needs to be between quotation marks. Like this:

function formatAmount(amount) { 
  return "$" + amount.toFixed(2);

Not sure, but it could be due to this. Let me know if this fixes it.

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.

1 Like

@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.