Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- const inputs = document.querySelectorAll('input');
- const checkBtn = document.querySelectorAll('button')[0];
- const clear = document.querySelectorAll('button')[1];
- const table = document.querySelector('table');
- const checkPar = document.querySelectorAll('#check p')[0];
- checkBtn.style.cursor = 'pointer';
- clear.style.cursor = 'pointer';
- const reset = () => {
- [...inputs].forEach((input) => {
- input.value = '';
- });
- table.style.border = 'none';
- checkPar.textContent = '';
- };
- const checkResult = () => {
- const matrix = [
- [inputs[0].value, inputs[1].value, inputs[2].value],
- [inputs[3].value, inputs[4].value, inputs[5].value],
- [inputs[6].value, inputs[7].value, inputs[8].value],
- ];
- let isSudomu = true;
- for (let i = 1; i < matrix.length; i++) {
- const row = matrix[i];
- const col = matrix.map((takeRow) => takeRow[i]);
- if (col.length !== [...new Set(col)].length || row.length !== [...new Set(row)].length) {
- isSudomu = false;
- break;
- }
- }
- if (isSudomu) {
- table.style.border = '2px solid green';
- checkPar.style.color = 'green';
- checkPar.textContent = 'You solve it! Congratulations!';
- } else {
- table.style.border = '2px solid red';
- checkPar.style.color = 'red';
- checkPar.textContent = 'NOP! You are not done yet...';
- }
- };
- clear.addEventListener('click', reset);
- checkBtn.addEventListener('click', checkResult);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement