Procházet zdrojové kódy

HW YB2NKR8B2LL done

Varvara Huza před 3 roky
rodič
revize
c462357419
2 změnil soubory, kde provedl 168 přidání a 0 odebrání
  1. 15 0
      Homework_10/index.html
  2. 153 0
      Homework_10/main.js

+ 15 - 0
Homework_10/index.html

@@ -0,0 +1,15 @@
+<!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">
+    <title>Document</title>
+</head>
+<body>
+    
+    <div class="multipleTable"></div>
+    
+    <script src="main.js"></script>
+</body>
+</html>

+ 153 - 0
Homework_10/main.js

@@ -0,0 +1,153 @@
+//Сама таблица Пифагора, такая же как и в домашке раньше
+let multiplyTable = []
+for (let i = 0; i <=10; i++) {
+    multiplyTable[i] = []
+    for (let j = 0; j <=10; j++) {
+        multiplyTable[i][j] = i * j
+    }
+}
+
+let tableContainer = document.querySelector('.multipleTable')
+
+let table = document.createElement('table')
+table.border = "1"
+for (let i = 0; i < multiplyTable.length; i++) {
+    let row = document.createElement('tr')
+
+    if (i == 0) {
+        let cell = document.createElement ('td')
+        cell.innerHTML = '&#9959;'
+        row.appendChild(cell)
+    } else {
+        let cell = document.createElement('td')
+        cell.innerText = i
+        row.appendChild(cell)
+    }
+
+    for (let j = 1; j < multiplyTable[i].length; j++) {
+        if (i == 0) {
+            let cell = document.createElement('td')
+            cell.innerText = multiplyTable[1][j]
+            row.appendChild(cell)
+        } else {
+            let cell = document.createElement('td')
+            cell.innerText = multiplyTable[i][j]
+            row.appendChild(cell)
+        }
+    }
+    
+    table.appendChild(row)
+}
+
+tableContainer.appendChild(table)
+
+//подсветка строки и столбца с замыканиями
+let cells = document.querySelectorAll('td');
+let rows = document.querySelectorAll('tr');
+
+function highlightRow (tr) {
+    let row = tr.children;
+    function highlightCell (td, tdCount) {
+        td.onmouseover = function () {
+            for (let column of rows) {
+                column.children[tdCount].style.backgroundColor = '#bcf'
+                column.children[tdCount].style.color = '#fff'
+            }
+
+            for (let rowCell of row) {
+                rowCell.style.backgroundColor = '#bcf'
+                rowCell.style.color = '#fff'
+            }
+            td.style.backgroundColor = '#6dd'
+            td.style.color = '#fff'
+        }
+        td.onmouseout = function () {
+            for (let column of rows) {
+                column.children[tdCount].style.backgroundColor = ''
+                column.children[tdCount].style.color = ''
+            }
+
+            for (let rowCell of row) {
+                rowCell.style.backgroundColor = ''
+                rowCell.style.color = ''
+            }
+            td.style.backgroundColor = ''
+            td.style.color = ''
+        }
+    }
+    return highlightCell;
+}
+
+for (let row of rows) {
+    let highlightCell = highlightRow(row);
+    let tdCounter = 0;
+    for (let cell of row.children) {
+        highlightCell(cell, tdCounter);
+        tdCounter++
+    }
+}
+
+//makeProfileTimer
+function makeProfileTimer () {
+    let startTime = performance.now()
+    function innerTimer () {
+        let endTime = performance.now()
+        let workTime = endTime - startTime;
+        return workTime;
+    }
+    return innerTimer;
+}
+
+
+//makeSaver
+function makeSaver (func) {
+    let result;
+    function returnResult () {
+        if (!result) {
+            result = func()
+        }
+        return result;
+    }
+    return returnResult;
+}
+
+//Final Countdown
+function countdown (numb) {
+    let counter = numb;
+    let countdown = setTimeout(function showCountdown () {
+        if (counter < 1) {
+            console.log('Поехали!')
+            return;
+        }
+        console.log(counter)
+        counter--
+        countdown = setTimeout(showCountdown, 1000)
+        }, 1000)
+}
+
+//MyBind
+    function myBind(functionToBind, context, args) {
+        function boundFunction (...newArgs) {
+            let commonArgs = []
+            let functionResult
+            let counter = 0
+            for (let argument of args) {
+                if (argument === undefined) {
+                    commonArgs.push(newArgs[counter])
+                    counter++
+                } else {
+                    commonArgs.push(argument)
+                }
+            }
+            if (context) {
+                context.key = functionToBind
+                functionResult = context.key(...commonArgs)
+                delete context.key
+            } else {
+                functionResult = functionToBind(...commonArgs)
+            }
+            return functionResult
+        }
+        return boundFunction
+    }
+