Анатолий Пивоварский 1 year ago
parent
commit
a443087110
3 changed files with 160 additions and 0 deletions
  1. 47 0
      HW 4/js/script.js
  2. 13 0
      HW 5/index.html
  3. 100 0
      HW 5/js/script.js

+ 47 - 0
HW 4/js/script.js

@@ -65,3 +65,50 @@ for(let i in persons){
 };
 
 //loop of loop of values
+for(let i in persons){ 
+    for (let values in persons[i]) {
+        console.log(persons[i] [values]);
+    }   
+};
+
+//fullName
+for(let i in persons) {
+    if (persons[i].name && persons[i].surname) {
+        persons[i].fullName = persons[i].name + " " + persons[i].surname;
+}
+    else if (persons[i].fathername) { 
+        persons[i].fullName = persons[i].name + " " + persons[i].fathername + " " + persons[i].surname;
+     }
+
+    console.log(persons[i].fullName)
+};
+
+//serialize
+JSON.stringify(persons);
+
+//deserialize
+
+persons.push(JSON.parse(`{"name":"Rocky", "surname":"Balboa"}`));
+
+//HTML
+let str = "<table border='1'>";
+for (let i = 0; i < persons.length; i++) {
+    for (let j in persons[i]) {
+        str += `<tr><td>${j}</td><td>${persons[i][j]}</td></tr>`
+    }
+}
+str += "</table>";
+console.log(str);
+document.write(str);
+
+//HTML tr color
+
+let strColor = "<table border='1'>";
+for(let i = 0; i < 4; i++){
+    for(let j in persons[i]) {
+        strColor += `<tr style = color:red;><td>${j}</td><td>${persons[i][j]}</td></tr>`
+    }
+}
+strColor +="</table>";
+console.log(strColor);
+document.write(strColor);

+ 13 - 0
HW 5/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="./js/script.js"></script>
+    
+</body>
+</html>

+ 100 - 0
HW 5/js/script.js

@@ -0,0 +1,100 @@
+function a(){
+    alert("Привет!");
+}
+a()
+//
+function cube(){
+    console.log(prompt(`число`)**3);
+}
+cube();
+//
+function avg2 (a, b){
+    console.log((a + b) / 2);
+}
+avg2(1,2);
+avg2(10,5);
+
+//
+function sum3 (a, b, c){
+        a = a || 0;
+        b = b || 0;
+        c = c || 0;
+        return(a + b + c);
+}
+sum3(1,2,3);
+sum3(5,10,100500);
+sum3(5,10);  
+
+//
+function intRandom (a, b){
+        a = a || 0;
+        b = b || 0;
+        let number = (Math.random() * (b - a) + a);
+        return Math.round(number);
+}
+console.log(intRandom(2, 15))
+console.log(intRandom(-1, -1))
+console.log(intRandom(0, 1))
+console.log(intRandom(10))
+
+//
+function greetAll() {
+    for(let i of arguments) {
+       alert(`Hello ${i}`)
+    }
+ }
+ greetAll("Superman")
+ greetAll("Superman", "SpiderMan")
+ greetAll("Superman", "SpiderMan", "Captain Obvious")
+
+ //
+ function sum (){
+    let resulta = 0;
+    for(let i of arguments){
+        resulta += i;
+    }
+    console.log(resulta);
+ }
+sum(1)
+sum(2)
+sum(10, 20, 40, 100)
+//
+
+function aSample(){
+    a("Привет!") // вызывает alert("Привет!")
+}
+
+function cubeSample(){
+    cube(5) // => 125
+}
+
+let sample = prompt("Введите название задания")
+switch (sample.toLowerCase()){
+    case "a": a()
+              break
+    case "cube": cube()
+              break
+    case "avg2": avg2()
+              break
+    case "sum3": sum3()
+              break
+    case "intRandom": intRandom()
+              break
+    case "greetAll": greetAll()
+              break
+    case "sum": sum()
+              break              
+}
+
+//
+let sampl = {
+    a: a(),
+    cube: cube(),
+    avg2: avg2(),
+    sum3: sum3(),
+    intRandom: intRandom(),
+    greetAll: greetAll(),
+    sum: sum()
+}
+let sampl1 = prompt("Введите название функции")
+alert(sampl1[`${sampl}`])