Validating Empty Squares TicTacToe - Javascript only -


first thank individuals helped me question before. ones decided close post without trying first assist me, please refrain closing post if not deciding , calling issue broad. also, i'm not looking of time "optimize" code or corrections how expatiate summary below. now, real issue...

i'm trying hand @ building tic-tac-toe game plain vanilla javascript, i'm hoping can stay in boundaries of keeping simple javascript. not optimize code!

what require following: need code check each square see if it's filled x or o. if squares still available, no need alert if squares filled, need alert me "no more moves!"

i have started function checkempty

thank assistance , time!

here code have got far:

<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title>tic tac toe</title>     <style>         td {              border: 1px solid black;             height: 250px;             width: 250px;             font-family: sans-serif;             font-size: 150pt;             text-transform: uppercase;         }     </style> </head> <body>     <table>         <tr>             <td align="center" id="square1" onclick="displaymarker('square1');"></td>             <td align="center" id="square2" onclick="displaymarker('square2');"></td>             <td align="center" id="square3" onclick="displaymarker('square3');"></td>         </tr>         <tr>             <td align="center" id="square4" onclick="displaymarker('square4');"></td>             <td align="center" id="square5" onclick="displaymarker('square5');"></td>             <td align="center" id="square6" onclick="displaymarker('square6');"></td>         </tr>         <tr>             <td align="center" id="square7" onclick="displaymarker('square7');"></td>             <td align="center" id="square8" onclick="displaymarker('square8');"></td>             <td align="center" id="square9" onclick="displaymarker('square9');"></td>         </tr>     </table>      <script>          var cp1 = 1;          function displaymarker(allsquares) {              if (document.getelementbyid(allsquares).innerhtml != "") {                 alert("choose square");             }             else {                  if (cp1 == 1) {                     document.getelementbyid(allsquares).innerhtml = "x";                     cp1 = 2;                 }                  else {                     document.getelementbyid(allsquares).innerhtml = "o";                     cp1 = 1;                 }             }             checkempty();         }         function checkempty() {              (var = 1; <= 9; i++) {                 console.log(document.getelementbyid('square' + i).innerhtml + " square" + i);              }      </script> </body> </html> 

should work:

function checkempty() {     (var = 1; <= 9; i++) {         if (!document.getelementbyid('square' + i).innerhtml) return;     }     alert("all squares filled"); } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -