-1

So I'm making an idle game and I want when you buy a 'carrot patch' in this example, the price of said 'carrot patch' will raise by 50%. However this doesn't happen.

Here's my code:

var patchPrice = 10;

function buyPatch() {
   if (affordable = true) {
      var patchPrice = patchPrice * 1.5;
   }
}

4 Answers4

2

you have declared the patchPrice variable twice. so it will overwrite the previous value. just remove the second var and it will work.

-1

These were problems with js before es6 I recommend you to use es6 const and let to declare variables.

-1

Try == in the comparison or simply omit the (== true) as it is already a boolean.

var patchPrice = 10;
function buyPatch() {
   if (affordable == true) {
      var patchPrice = patchPrice * 1.5;
   }
}
Lucas A
  • 1
  • 1
-1

Avoid using "VAR" unless you wanna work with function scope variables.

ab.eth
  • 1