The code on this condition is not executed: if(example % 2 == 0) .

 var check=$("#timer").html(); var example=check; if(example % 2 == 0 ) { $('#second').click(function() { $(this).css('background-image', 'url(X.png)'); example++; $("#timer").html(example); }); } else { $('#first').click(function() { $(this).css('background-image', 'url(Zero.png)'); example++; $("#timer").html(example); }); } 
 .general { border: 1px solid #000000; width: 150px; height: 150px; background-color: #05EFFF; } table { margin: 0 auto; margin-top: 15%; } 
 <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <meta http-equiv="Content-Type" content="text/html charsеt=utf-8"> <title>TIC-TAC-TOE</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js" ></script> </head> <body> <table> <tr> <td><div id="first" class="general"></div></td><td><div id="second" class="general"></div></td><td><div id="third"class="general" ></div></td> </tr> <tr> <td><div id="fourth" class="general" ></div></td><td><div id="fiveth" class="general" ></div></td><td><div id="sixth" class="general" ></div></td> </tr> <tr> <td><div id="seventh" class="general" ></div></td><td><div id="eightth" class="general" ></div></td><td><div id="nineth" class="general" ></div></td> </tr> </table> <p id="timer" >1</p> <script type="text/javascript" src="js.js"></script> </body> </html> 

enter image description here enter image description here

Closed due to the fact that off-topic participants Dmitriy Simushev , user194374, pavel , Yuri , aleksandr barakin Jan 8 '17 at 12:01 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Dmitriy Simushev, Community Spirit, pavel, Yuri, aleksandr barakin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • $("#timer").html(); gets the string ....... you need an integer ...... you need to use parseInt developer.mozilla.org/ru/docs/Web/JavaScript/Reference/… - Alexey Shimansky
  • Does not change the situation. - Andrew_Romanuk
  • How do you determine what does not change the situation? I am the number 2 and the rules .... I'm looking at the debugger, and you? - Alexey Shimansky
  • I write in code, and then I launch it in the browser. - Andrew_Romanuk
  • and check ..... - Andrew_Romanuk

1 answer 1

 $(".general").click(function() { if (example % 2 == 0) { $(this).css('background-color', 'red'); example++; $("#timer").html(example); } else { $(this).css('background-color', 'yellow'); example++; $("#timer").html(example); } }) 

 var check = $("#timer").html(); var example = check; $(".general").click(function() { if (example % 2 == 0) { $(this).css('background-color', 'red'); example++; $("#timer").html(example); } else { $(this).css('background-color', 'yellow'); example++; $("#timer").html(example); } }) 
 .general { border: 1px solid #000000; width: 150px; height: 150px; background-color: #05EFFF; } table { margin: 0 auto; margin-top: 15%; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr> <td> <div id="first" class="general"></div> </td> <td> <div id="second" class="general"></div> </td> <td> <div id="third" class="general"></div> </td> </tr> <tr> <td> <div id="fourth" class="general"></div> </td> <td> <div id="fiveth" class="general"></div> </td> <td> <div id="sixth" class="general"></div> </td> </tr> <tr> <td> <div id="seventh" class="general"></div> </td> <td> <div id="eightth" class="general"></div> </td> <td> <div id="nineth" class="general"></div> </td> </tr> </table> <p id="timer">2</p>