AntonPyvovarov 1 year ago
parent
commit
d3c0d21808
5 changed files with 108 additions and 4 deletions
  1. 0 3
      HW4/main.js
  2. 1 1
      HW5/main.js
  3. 24 0
      HW7/index.html
  4. 60 0
      HW7/main.js
  5. 23 0
      HW7/style.css

+ 0 - 3
HW4/main.js

@@ -104,9 +104,6 @@
     let cycle = confirm();
     while (cycle == false) {
         cycle = confirm();
-        if (cycle) {
-            break;
-        }
     }
 
     // array fill

+ 1 - 1
HW5/main.js

@@ -109,7 +109,7 @@ console.log(persons)
 // HTML
 
 let str = "<table border='1'>";
-for (let i = 0; i < 4; i++) {
+for (let i = 0; i < persons.length; i++) {
     for (let key in persons[i]) {
         str += `<tr><td>${[key]}</td><td>${persons[i][key]}</td></tr>`;
     }

+ 24 - 0
HW7/index.html

@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="style.css">
+    <title>HW7</title>
+</head>
+
+<body>
+    <main class="main">
+        <div class="wrapper">
+            <input type="number" id='firstNumber' placeholder="Enter first number"> *
+            <input type="number" id='secondNumber' placeholder="Enter second number">
+            <button id='calc'>Press from calc</button>
+            <input type="number" value="0" id="result">
+        </div>
+    </main>
+    <script src="main.js"></script>
+</body>
+
+</html>

+ 60 - 0
HW7/main.js

@@ -0,0 +1,60 @@
+//Таблица умножения
+
+let table = document.createElement('table');
+for (let i = 0; i < 10; i++) {
+    let row = document.createElement('tr');
+    for (let j = 0; j < 10; j++) {
+        let col = document.createElement('td');
+        let val = i * j;
+        if (val === 0) {
+            val = i || j;
+        }
+        col.innerHTML = val;
+        row.appendChild(col);
+    }
+
+    table.appendChild(row);
+}
+
+document.body.appendChild(table);
+
+// Подсвет ячейки и подсвет строки и столбца
+
+table.onmouseover = function (event) {
+    let target = event.target;
+    target.style.background = 'yellow';
+
+    document.querySelectorAll(".highlight").forEach(
+        item => item.classList.remove("highlight")
+    );
+    target.closest("tr").classList.add("highlight");
+    target.closest("table").querySelectorAll("tr").forEach(
+        row => row.cells[target.cellIndex].classList.add("highlight")
+    );
+};
+
+table.onmouseout = function (event) {
+    let target = event.target;
+    target.style.background = '';
+
+    document.querySelectorAll(".highlight").forEach(
+        item => item.classList.remove("highlight")
+    );
+};
+
+//Calc
+
+const numberOne = document.getElementById('firstNumber')
+const numberSecond = document.getElementById('secondNumber')
+calc.onclick = function () {
+    result.value = ((+numberOne.value) * (+numberSecond.value))
+}
+
+
+//Calc Live
+
+// function calc() {
+//     result.value = ((+numberOne.value) * (+numberSecond.value))
+// }
+// numberOne.oninput = calc
+// numberSecond.oninput = calc

+ 23 - 0
HW7/style.css

@@ -0,0 +1,23 @@
+table {
+    margin: 10px auto;
+    border-collapse: collapse;
+}
+
+td {
+    border: 2px solid grey;
+    padding: 15px;
+    text-align: center;
+}
+
+input {
+    margin: 0 10px;
+}
+
+.wrapper {
+    display: flex;
+    justify-content: center;
+}
+
+.highlight {
+    background: lightblue;
+}