浏览代码

finish HW 7

serg155alternate 2 年之前
父节点
当前提交
0fd7c533f6
共有 2 个文件被更改,包括 49 次插入40 次删除
  1. 13 14
      HW10 Closures and scopes/script.js
  2. 36 26
      HW7 DOM Base/script.js

+ 13 - 14
HW10 Closures and scopes/script.js

@@ -79,7 +79,6 @@ alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt б
 
 
 let counter = 5;
-
 function countdown() {
     console.log(counter);
     let int1 = setTimeout(() => {
@@ -95,11 +94,11 @@ function countdown() {
         console.log('GOGOGO');
     }
 };
-countdown();
+//countdown();
 
 
 /* 
-//cheeter
+//))cheeter
 let counter = 5;
 function countdown() {
     console.log(counter);
@@ -116,6 +115,8 @@ function countdown() {
 
 let int1 = setInterval(() => {countdown()}, 1000); */
 
+
+
 //myBind
 
 /* let pow5 = myBind(Math.pow, Math, [undefined, 5]) // первый параметр - функция для биндинга значений по умолчанию, 
@@ -141,12 +142,11 @@ myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefin
 
 
 function myBind(func, funcThis, arr) {
-    let bindArray = arr;
-    let funcRes = func.bind(funcThis, ...bindArray);
-
+    let funcRes = func.bind(...arr);
+    console.log(arr);
     function retFunc(...params) {
-
-        console.log(bindArray);
+        console.log(arr);
+        console.log(params);
         return funcRes(...params);
     }
     return retFunc;
@@ -157,9 +157,8 @@ console.log(myBind(Math.pow, Math, [undefined, 5]));
 console.log(myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a', 'c', 'd'));
 
 
-/* console.log([undefined, 'b', undefined, undefined, 'e', 'f'].map((item, i) => {
-    if( item[i] ==='undefined') {
-        console.log(i);       
-         item[i] = ['a','c','d'][i]
-       }
-})) */
+
+
+
+
+  

+ 36 - 26
HW7 DOM Base/script.js

@@ -5,18 +5,18 @@
 и innerText. Создайте таблицу, вложенные строки и ячейки в циклах.  */
 
 
- let root = document.querySelector('.root');
+let root = document.querySelector('.root');
 
-for (let i = 0; i < 10; i++){
+for (let i = 0; i < 10; i++) {
 
     let tr = document.createElement('tr');
-    
+
     root.append(tr);
-    
-    for (let k = 0; k < 10; k++){
+
+    for (let k = 0; k < 10; k++) {
 
         let td = document.createElement('td');
-        
+
         if (i === 0) {
             td.innerText = k;
             tr.append(td);
@@ -26,9 +26,9 @@ for (let i = 0; i < 10; i++){
         } else {
             td.innerText = i * k;
             tr.append(td);
-        }  
+        }
     }
-} 
+}
 
 /* Подсветить ячейку над которой находится курсор мыши.
  Используйте события mouseover и mouseout, 
@@ -52,28 +52,38 @@ let td = document.querySelectorAll('td');
 
 
 
- td.forEach((item, i) => {
+td.forEach((item, i) => {
     item.onmouseover = (e) => {
-        
-       item.style.backgroundColor = 'yellow'; 
-       item.parentNode.style.backgroundColor = 'green';
-      
-       if (td[i].cellIndex === e.target.cellIndex){
-        for (let i = 0; i < td.length/10; i++ ){
-            console.log(td[i].cellIndex)
-        };
-           
-          
-      }; 
-       
-    } 
+
+        item.style.backgroundColor = 'yellow';
+        item.parentNode.style.backgroundColor = 'green';
+        let trCollect = Array.from(item.parentElement.parentElement.children);
+        trCollect.forEach((el, i) => {
+            // console.log(el.children[i].cellIndex);
+            //console.log(item.cellIndex);
+            if (el.children[i].cellIndex === item.cellIndex) {
+                Array.from(el.parentElement.children).forEach(elem => elem.children[i].style.backgroundColor = 'red');
+            }
+        });
+    };
 
     item.onmouseout = () => {
         item.style.backgroundColor = '';
         item.parentNode.style.backgroundColor = '';
+        let trCollect = Array.from(item.parentElement.parentElement.children);
+        trCollect.forEach((el, i) => {
+            if (el.children[i].cellIndex === item.cellIndex) {
+                Array.from(el.parentElement.children).forEach(elem => elem.children[i].style.backgroundColor = '');
+            }
+
+        });
     }
 })
 
+
+
+
+
 //Calc + Calc Live 
 
 
@@ -106,7 +116,7 @@ checkLiter.addEventListener('change', () => {
     if (checkLiter.checked && fuel.value && way.value) {
         priceInput.style.display = 'none';
         calcMyConsumption(fuel.value, way.value);
-       
+
     } else {
         outer.textContent = `Заполните все формы`;
 
@@ -115,12 +125,12 @@ checkLiter.addEventListener('change', () => {
 
 
 checkUah.addEventListener('change', () => {
-    if (checkUah.checked && fuel.value && way.value ) {
+    if (checkUah.checked && fuel.value && way.value) {
         priceInput.style.display = 'block';
         price.value = '';
         outer.textContent = `Внесите цену`;
         price.addEventListener('input', () => calcMyConsumption(fuel.value, way.value, price));
-    
+
     } else {
         outer.textContent = `Заполните данные формы`;
 
@@ -128,7 +138,7 @@ checkUah.addEventListener('change', () => {
 })
 
 reset.addEventListener('click', () => {
-    fuel.value = ''; 
+    fuel.value = '';
     way.value = '';
     price.value = '';
     outer.textContent = '';