Ivar 2 years ago
parent
commit
aae131b9a4
6 changed files with 267 additions and 13 deletions
  1. 81 3
      js/05/index.js
  2. 112 10
      js/06/index.js
  3. 13 0
      js/07/index.html
  4. 24 0
      js/07/index.js
  5. 13 0
      js/08/index.html
  6. 24 0
      js/08/index.js

+ 81 - 3
js/05/index.js

@@ -232,7 +232,7 @@ function HTMLTrColor() {
    document.write(str)
 }
 
-HTMLThOptional()
+// HTMLThOptional()
 function HTMLThOptional() {
    let persons = arrayOfPersons()
    let sampleLength  = 0
@@ -245,12 +245,23 @@ function HTMLThOptional() {
       }
    }
    let j = 0
-   for (const element of persons) {
+   for (let n = 0; n < persons.length; n++) {
+      let element = persons[n]
+
+      if (n === 0) {
+         str += '<tr>'      
+         for (let i = 0; i < sampleLength; i++) {  
+            str += `<th>${sampleKeys[i]}</th>`
+         }
+         str += '</tr>'
+      } 
+
       if (j % 2 === 0) {
          str += '<tr style="background-color: #999999">'
       } else {
          str += '<tr>'      
       }
+
       for (let i = 0; i < sampleLength; i++) {  
                 
          if (sampleKeys[i] in element) {
@@ -267,7 +278,7 @@ function HTMLThOptional() {
    document.write(str)
 }
 
-HTMLConstructor()
+// HTMLConstructor()
 function HTMLConstructor() {
    let body = {
       tagName: 'body',
@@ -316,6 +327,73 @@ function HTMLConstructor() {
           }
       ]
    }
+
+// если у тега нет детей, то считется, что он одиночный
+
+   let str = ''
+   str += `<${body.tagName}`
+      if (body.attrs) {
+         for (let [key, value] of Object.entries(body.attrs)) {
+            str += ` ${key}="${value}"`
+         }
+      }
+   str += `>`   
+      if (body.children) {
+         if (typeof body.children === 'object') {
+            for (let obj of body.children) {
+
+               str += `<${obj.tagName}`
+               if (obj.attrs) {
+                  for (let [key, value] of Object.entries(obj.attrs)) {
+                     str += ` ${key}="${value}"`
+                  }
+               }
+               if (obj.children) {
+                  str += `>`
+
+                  if (typeof obj.children === 'object') {
+
+                     for (let obj2 of obj.children) {
+            
+                        str += `<${obj2.tagName}`
+                        if (obj2.attrs) {
+                           for (let [key2, value2] of Object.entries(obj2.attrs)) {
+                              str += ` ${key2}="${value2}"`
+                           }
+                        }
+      
+                        if (obj2.children) {
+                           str += `>`
+
+                           if (typeof obj2.children === 'object') {
+
+                           } else {
+                              str += `${obj2.children}`
+                           }
+                           str += `</${obj2.tagName}>`  
+                        } else {
+                           str += `/>`
+                        }
+      
+                     }
+                  } else {
+                     str += `${obj.children}`
+                  }
+                        
+                  str += `</${obj.tagName}>` 
+               } else {
+                  str += `/>`
+               }
+ 
+            }
+         } else {
+            str += `${body.children}`
+         }
+      }
+   str += `</${body.tagName}>`   
+
+   console.log(str)   
+   document.write(str)
 }
 
 // destructArray()

+ 112 - 10
js/06/index.js

@@ -1,24 +1,126 @@
-htmlTree()
-function htmlTree() {
+// a('УУУУУУУУУУУ')
+function a(text) {
+   alert(text)
+}
+
+// console.log(cube(2))
+function cube(number) {
+   return number ** 3
+}
 
+// console.log(avg2(1,2))
+function avg2(number1, number2) {
+   return (number1 + number2) / 2
 }
 
-htmlTree()
-function htmlTree() {
+// console.log(sum3(10,5))
+function sum3(num1 = 0, num2 = 0, num3 = 0) {
+   return +num1 + +num2 + +num3
+}
 
+// console.log(intRandom(100))
+function intRandom(bottom, top = 0) {
+   let range = top - bottom
+   let inputNum = Math.random()
+   let output = Math.round((range * inputNum) + bottom)
+   return output
 }
 
-htmlTree()
-function htmlTree() {
+// console.log(greetAll('AAAAA','UUUUUU','gUuuUuu'))
+function greetAll() {
+   let str = 'Hello '
+   for (let i = 0; i < arguments.length; i++) {
+      if (i < (arguments.length - 1)) {
+         str += arguments[i]
+         str += ', '
+      } else {
+         str += arguments[i]
+      }
+   }
+   alert(str)
+}
 
+// console.log(sum(10,5,1,2,1,2,100))
+function sum() {
+   let num = 0
+   for (let i = 0; i < arguments.length; i++) {
+      num += +arguments[i]
+   }
+   return num
 }
 
-htmlTree()
-function htmlTree() {
+function aSample() {
+   a("Привет!")
+}  
+function cubeSample() {
+   console.log(cube(5))
+}
+function avg2Sample() {
+   console.log(avg2(1,2))
+   console.log(avg2(10,5))
+}
+function sum3Sample() {
+   console.log(sum3(1,2,3))
+   console.log(sum3(5,10,100500))
+   console.log(sum3(5,10))
+}
+function intRandomSample() {
+   console.log(intRandom(2,15))
+   console.log(intRandom(-1,-1))
+   console.log(intRandom(0,1))
+   console.log(intRandom(10))
+}
+function greetAllSample() {
+   greetAll("Superman")
+   greetAll("Superman", "SpiderMan")
+   greetAll("Superman", "SpiderMan", "Captain Obvious")
+}
+function sumSample() {
+   console.log(sum(1))
+   console.log(sum(2))
+   console.log(sum(10,20,40,100))
+}
 
+// union()
+function union() {  
+   let chooser = prompt("Введите название задания")
+   switch (chooser.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
+   }
 }
 
-htmlTree()
-function htmlTree() {
+// unionDeclarative()
+function unionDeclarative() {
+   let chooser = prompt("Введите название задания")
 
+   chooserFunc(chooser)
+   function chooserFunc(sample) {
+      const samples = {
+         a: function () {
+            return aSample()
+         },
+         cube: function () {
+            return cubeSample()
+         },
+         avg2: () => avg2Sample(),
+         sum3: () => sum3Sample(),
+         intrandom: () => intRandomSample(),
+         greetall: () => greetAllSample(),
+         sum: () => sumSample(),
+      }
+      return samples[sample.toLowerCase()]?.() || console.log("sample not found")
+   }
 }

+ 13 - 0
js/07/index.html

@@ -0,0 +1,13 @@
+<!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 src="./index.js"></script>
+</body>
+</html>

+ 24 - 0
js/07/index.js

@@ -0,0 +1,24 @@
+htmlTree()
+function htmlTree() {
+
+}
+
+htmlTree()
+function htmlTree() {
+
+}
+
+htmlTree()
+function htmlTree() {
+
+}
+
+htmlTree()
+function htmlTree() {
+
+}
+
+htmlTree()
+function htmlTree() {
+
+}

+ 13 - 0
js/08/index.html

@@ -0,0 +1,13 @@
+<!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 src="./index.js"></script>
+</body>
+</html>

+ 24 - 0
js/08/index.js

@@ -0,0 +1,24 @@
+htmlTree()
+function htmlTree() {
+
+}
+
+htmlTree()
+function htmlTree() {
+
+}
+
+htmlTree()
+function htmlTree() {
+
+}
+
+htmlTree()
+function htmlTree() {
+
+}
+
+htmlTree()
+function htmlTree() {
+
+}