Initial condition (IF) does not work

Asked

Viewed 145 times

0

I’m trying to make an old game. So far I managed to make the appointments change every turn and the function to delete the appointments.

ps: I’m using black and red color instead of ball and "x".

My problem is that the markings change even after they are marked if you click on it again. I want once clicked the elements keep their markings (bgcolor).

http://jsfiddle.net/11nokxho/1

For this I tried to solve by putting the first if checking if the background does not have white initial color, if it does not have false return and stop the function.

if(!casa.style.backgroundColor == "#FFF") return false;

Since it doesn’t work.

1 answer

5


The logical operator for different is: !=

And the return of property style.backgroundColor is in rgb(x,x,x) and not in hexacolor, so try the following syntax:

if(casa.style.backgroundColor != "rgb(255, 255, 255)" && casa.style.backgroundColor != "") return false;

Jsfiddle

  • About the operator: ! home.style.backgroundColor == "rgb(255, 255, 255)". Of course it is, isn’t it? I’m confused. At last

  • I do not understand why it worked to change color even in HEX and did not work for the first test?

  • I can’t remember if I marked you.

  • 1

    @ropbla9 Using the ! in front of the expression indicates that you want to do the inversion of the result, but only works with boleanos, in case, casa.style.backgroundColor returns a string, to work as expected, you have to enclose with parentheses like this: !(casa.style.backgroundColor == "rgb(255, 255, 255)") soon find easier to use != directly...

  • and on the second comment?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.