Browse Source

HW<7> done>

Levshin95 1 year ago
parent
commit
e523474d6c
5 changed files with 103 additions and 83 deletions
  1. 3 7
      HW5/index.js
  2. 31 16
      HW6/index.js
  3. 19 0
      HW7/index.html
  4. 50 0
      HW7/index.js
  5. 0 60
      training.html

+ 3 - 7
HW5/index.js

@@ -124,10 +124,7 @@
 /* destruct string */
 
     let arr2 = [1, "abc"]
-    let number = arr2[0]
-    let s1 = arr2[1][0]
-    let s2 = arr2[1][1]
-    let s3 = arr2[1][2]
+    let [number, [s1, s2, s3]] = arr2
 
 /* destruct 2 */
 
@@ -135,10 +132,9 @@
             surname: 'Petrov',
             children: [{name: 'Maria'}, {name: 'Nikolay'}]}
     
-        let name1 = obj.children[0]
-        let name2 = obj.children[1]
+    let {children: [{name: name1}, {name: name2}]} = obj
 
 /* destruct 3 */
 
         let arr3 = [1, 2, 3, 4, 5, 6, 7, 10];
-        let [a, b, { length = arr3.length }] = arr3
+        let {'0':a, '1':b, length} = arr3

+ 31 - 16
HW6/index.js

@@ -24,12 +24,10 @@
 
 /* sum3 */
 
-    function sum3(a2, b2, c2) {
-        return a2 + b2 + c2 
+    function sum3(a2 = 0, b2 = 0, c2 = 0) {
+    let sum1 = (a2 + b2 + c2)
+        return sum1 
     }
-    let a2 = +prompt('Enter a number')
-    let b2 = +prompt('Enter a number')
-    let c2 = +prompt('Enter a number')
     sum3(a2, b2, c2)
 
 /* intRandom */
@@ -45,12 +43,15 @@
 /* greetAll */
 
     function greetAll() {
-        for (let i = 0; i < arguments.length; i++) {
-            alert("Hello, " + arguments[i]);
+        let greetAll1 = " "
+            for (let i = 0; i < arguments.length; i++) {
+                greetAll1 += " " + arguments[i] + ","
+            }
+                alert("Hello, " + greetAll1);
         }
-    }
 
-    greetAll(prompt('Enter a name'))
+
+    greetAll("superman", "Spiderman", "Бетмен")
 
 /* sum */
 
@@ -119,11 +120,25 @@
 /* Union declarative */
 
     let unionDeclarative = {
-        a: aSample(),
-        cube: cubeSample(),
-        avg2: avg2Sample(),
-        sum3: sum3Sample(),
-        intRandom: intRandomSample(),
-        greetAll: greetAllSample(),
-        sum: sumSample()
+        a(){
+            a("Привет!")
+        },
+        cube(){
+            cube(5)
+        },
+        avg2(){
+            avg2(2, 2)
+        },
+        sum3(){
+            sum3(1, 2, 3)
+        },
+        intRandom(){
+            intRandom(2,10)
+        },
+        greetAll(){
+            greetAll('Superman')
+        },
+        sum() {
+            sum(1, 4, 7)
+        }
     }  

+ 19 - 0
HW7/index.html

@@ -0,0 +1,19 @@
+<!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>
+        <input type="number" id="calc1"> + 
+        <input type="number" id="calc2">
+        <button id="calc">Результат</button>
+        <input type="number" id="result">
+    </div>
+    
+    <script src="index.js"> </script>
+</body>
+</html>

+ 50 - 0
HW7/index.js

@@ -0,0 +1,50 @@
+/* Таблица умножения */
+
+let table = document.createElement("table")
+document.body.append(table)
+
+    for(let i = 1; i < 10; i ++) {
+        let tr = document.createElement("tr")
+        table.append(tr)
+
+        for (let j = 1; j < 10; j++) {
+            let td = document.createElement("td")
+            tr.append(td)
+            td.innerText = i * j 
+            td.style.border = "1px solid black"
+            td.style.padding = "7px"
+        }
+    }
+
+/* Подсветить ячейку */
+
+let backlight = document.querySelectorAll("td")
+
+backlight.forEach(tdOn => tdOn.onmousemove = function() {
+    this.style.backgroundColor = "red"
+})
+
+backlight.forEach(tdOut => tdOut.onmouseout = function () {
+    this.style.backgroundColor = "white"
+})
+
+/* Подсветить стену и столбец */
+
+
+/* Расчет */
+
+let calc1 = document.getElementById("calc1")
+let calc2 = document.getElementById("calc2")
+
+    calc.onclick = function () {
+                alert(+calc1.value + +calc2.value);
+            };
+
+/* Расчет в реальном времени */
+
+function calc() {
+    result.value = (+calc1.value) + (+calc2.value)
+}
+
+calc1.oninput = calc
+calc2.oninput = calc

+ 0 - 60
training.html

@@ -1,60 +0,0 @@
-<!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>
-<script>
-
-function aSample(){
-    a("Привет!") 
-}
-
-function cubeSample(){
-    cube(5) 
-}
-
-function avg2Sample(){
-    avg2(2, 2)
-}
-
-function sum3Sample(){
-    sum3(1, 2, 3)
-}
-
-function intRandomSample(){
-    intRandom(2,10)
-}
-
-function greetAllSample() {
-    greetAll('Superman')
-}
-
-function sumSample(){
-    sum(1,4,7)
-}
-
-
-var sample = prompt("Введите название задания")
-switch (sample.toLowerCase()){
-    case "a": aSample()
-              break;
-    case "cube": cubeSample()
-              break;
-    case "avg2": avg2Sample()
-              break;
-    case "sum3": sum3Sample()
-              break;
-    case "intRandom": intRandomSample()
-              break;
-    case "greetAll": greetAllSample()
-              break;
-    case "sum": sumSample()
-              break;
-}
-</script>
-</body>
-</html>