if (gold >= 5 || (item1 = false) ) {
item1 = true;
gold = gold - 5;
}
This will keep going even if item1 is true. I'd like for the function to not run if either of those are not met. Thank you
if (gold >= 5 || (item1 = false) ) {
item1 = true;
gold = gold - 5;
}
This will keep going even if item1 is true. I'd like for the function to not run if either of those are not met. Thank you
You have to understand the difference between assignment (=
) and equivalence comparison (==
). Your code is assigning the value of false to the variable item1. To evaluate the value of item1, use:
if (gold >= 5 || item1 == false ) {
item1 = true;
gold = gold - 5;
}
Also, the additional nesting within parentheses is not necessary.
Try to change this:
if (gold >= 5 || (item1 = false) ) { item1 = true; gold = gold - 5; }
With this:
if (gold >= 5 || (item1 == false) ) { item1 = true; gold = gold - 5; }
With 2 = signs you check the equivalence. With 1 = sign you are assigning the variabile, noto comparing it. Hope this helps
Item1 = false is an assignment which will always evaluate as false.
You need item1 == false