Advertisement
Alexvans

sudoku

Aug 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <meta charset="UTF-8">
  5. <head>
  6.    <title>Sudoku</title>
  7.    <style>
  8.       table {
  9.          border-collapse: collapse;
  10.       }
  11.       td {
  12.          border: 1px solid black;
  13.          width: 30px;
  14.          height: 30px;
  15.       }
  16.       input {
  17.          width: 30px;
  18.          height: 30px;  
  19.       }
  20.       .boton {
  21.          width: 100px;
  22.       }
  23.       #rejilla {
  24.          float: left;
  25.       }
  26.    </style>
  27. </head>
  28. <body onload="crea_rejilla(document.getElementById('rejilla'))">
  29.  
  30.    <table id="rejilla">
  31.    </table>
  32.    <div id="botones">
  33.       <input type="button" value="Checar" onclick="checa( )" class="boton">
  34.       <input type="button" value="Limpiar" onclick="limpia( )" class="boton">
  35.    </div>
  36.  
  37.    <script>
  38.       let n = 9
  39.       let matriz = [ ]
  40.  
  41.       function valida_input(evento) {
  42.          let cadena = String.fromCharCode(evento.which)
  43.          if (!/\d/.test(cadena) || this.value.length != 0) {
  44.             evento.preventDefault( )
  45.          }
  46.       }
  47.  
  48.       function crea_rejilla(tabla) {
  49.          for (let i = 0; i < n; ++i) {
  50.            let fila = document.createElement("tr")
  51.            for (let j = 0; j < n; ++j) {
  52.               let celda = document.createElement("td")
  53.               celda.id = "c" + i + "_" + j
  54.  
  55.               let entrada = document.createElement("input")
  56.               entrada.addEventListener("keypress", valida_input)
  57.               entrada.id = "c" + i + "_" + j
  58.               entrada.value = "1"
  59.  
  60.               celda.appendChild(entrada)
  61.               fila.appendChild(celda)
  62.            }
  63.            tabla.appendChild(fila)
  64.            matriz.push(new Array(n))
  65.         }
  66.          
  67.         for (let i = 0; i < n; ++i) {
  68.            for (let j = 0; j < n; ++j) {
  69.              matriz[i][j] = false
  70.            }
  71.         }
  72.      }
  73.  
  74.      function vacia( ) {
  75.         for (let i = 0; i < 9; ++i) {
  76.            for (let j = 0; j < 9; ++j) {
  77.               let casilla = document.getElementById("c" + i + "_" + j).value
  78.               if (casilla == "" || casilla == null) {
  79.                  return true
  80.               }
  81.            }
  82.         }
  83.         return false
  84.      }
  85.  
  86.      function checa( ) {
  87.         console.log('entre')
  88.         if (!vacia( )) {
  89.            console.log("esta lleno")
  90.         } else {
  91.            console.log("Hay casillas vacías!")
  92.         }
  93.      }
  94.   </script>
  95.  
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement