3 Commit-ok 1f354639d1 ... bc160a70dc

Szerző SHA1 Üzenet Dátum
  OleksiiL bc160a70dc HW tree structure: SOME changes 2 éve
  OleksiiL 14292d8cac Rewrite some in 15HW 2 éve
  OleksiiL 7250485081 HW 13 rewrite 2 éve

+ 24 - 17
Homework_13/main.js

@@ -36,16 +36,19 @@
 
 // // Number: odd------------------------------------------------------------------------------------------;
 
-// // let Number = prompt("Enter any number", +0);
+// let Number = +prompt("Enter any number");
 
-// // const result2 = Number % 2;
-
-// // if (result === 0) {
-// //   alert("even number");
-// // }
-// // if (result === 1) {
-// //   alert("odd number");
-// // }
+// const result2 = Number % 2;
+// if (isNaN(result2)) {
+//   alert("Enter a number, please");
+// } else {
+//   if (result2 === 0) {
+//     alert("even number");
+//   }
+//   if (result2 === 1) {
+//     alert("odd number");
+//   }
+// }
 
 // // String: greeting-------------------------------------------------------------------------------------;
 
@@ -85,7 +88,7 @@
 
 // let satiety = confirm("Did you eat anything for breakfast?");
 
-// // if (satiety === true) {
+// // if (satiety) {
 // //   alert("it`s good you take care about your health");
 // // } else {
 // //   alert("Oh no, eat something now!!!");
@@ -93,7 +96,7 @@
 
 // let passOnParty = confirm("Are you older than 18?");
 
-// // if (passOnParty === true) {
+// // if (passOnParty) {
 // //   alert("You can passed");
 // // } else {
 // //   alert("You can not passed on party");
@@ -101,7 +104,7 @@
 
 // let canBuy = confirm("Are you older than 18 years?");
 
-// // if (canBuy === true) {
+// // if (canBuy) {
 // //   alert("You can buy bottle of beer");
 // // } else {
 // //   alert("you are so young for it");
@@ -129,7 +132,7 @@
 
 // // Object: real-------------------------------------------------------------------------------------------;
 
-// let myNoteBook = {
+// let myLaptop = {
 //   brand: "Lenovo",
 //   model: "Legion",
 //   CPU: "AMD Ryzen",
@@ -161,9 +164,9 @@
 
 // // Object: change-----------------------------------------------------------------------------------------;
 
-// myNoteBook.RAM = "32 GB";
-// myNoteBook.brand = "Asus";
-// myNoteBook.model = "Zephirus";
+// myLaptop.RAM = "32 GB";
+// myLaptop.brand = "Asus";
+// myLaptop.model = "Zephirus";
 // dreamCar.brand = "Suzuki";
 // dreamCar.model = "Vitara";
 
@@ -267,7 +270,7 @@
 // gender === true ? alert("You are a woman") : alert("You are a man");
 
 // // Синий пояс Number: flats-------------------------------------------------------------------------------;
-debugger;
+
 let numberOfFloors = prompt("how many floors in your house?", []);
 let numberOfFlats = prompt("How many apartments per floor in your house?", []);
 let yourApartmentNumber = prompt("Enter? please number of your apartment");
@@ -285,6 +288,10 @@ let yourFloor = Math.ceil(
     numberOfFlats
 );
 
+if (yourFloor === 0) {
+  yourFloor += 1;
+}
+
 alert(
   `Your apartment is located in the ${entranceNumber} entrance, on the ${yourFloor} flor`
 );

+ 53 - 50
Homework_15/tree_structure.js

@@ -100,46 +100,54 @@ console.log(body.subTags[0].subTags[3].attrs.id);
 // };
 
 // object links---------------------------------------------------------------------------------------------;
-// let clientsCar = {
-//   brand: prompt("Enter a brand car"),
-//   model: prompt("Enter a model of car"),
-//   volume: +prompt("choose volume of your future car"),
-//   color: prompt("What color you wish?"),
-//   HP: +prompt("Enter horse power what you need"),
-//   owner: clientCard.name,
-// };
 
-// let clientCard = {
-//   name: prompt("Enter your name, please"),
-//   surname: prompt("Enter your surname, please"),
-//   age: +prompt("Enter your age, please"),
-//   education: prompt(
-//     "enter your educational level (higher education, secondary education, etc."
-//   ),
-//   gender: prompt("choose your gender: man, woman"),
-//   sallery: +prompt("what is your annual income?"),
-//   car: clientsCar.brand,
-//   notebook: noteOfDream.brand,
-// };
+let clientsCar = {
+  brand: prompt("Enter a brand car"),
+  model: prompt("Enter a model of car"),
+  volume: +prompt("choose volume of your future car"),
+  color: prompt("What color you wish?"),
+  HP: +prompt("Enter horse power what you need"),
+};
+
+let clientCard = {
+  name: prompt("Enter your name, please"),
+  surname: prompt("Enter your surname, please"),
+  age: +prompt("Enter your age, please"),
+  education: prompt(
+    "enter your educational level (higher education, secondary education, etc."
+  ),
+  gender: prompt("choose your gender: man, woman"),
+  sallery: +prompt("what is your annual income?"),
+};
+
+let noteOfDream = {
+  brand: prompt("what brand of laptop would you like?"),
+  model: prompt("select laptop model "),
+  CPU: prompt("select the CPU"),
+  GPU: prompt("choose graphics: built-in or discrete "),
+  GPU_memory: +prompt(
+    "if you chose discrete graphics, select the amount of video memory you want "
+  ),
+  display: {
+    width: +prompt("enter width of resolution"),
+    height: +prompt("enter height of resolution"),
+    refresh_rate: prompt("What level of screen refresh is right for you?"),
+  },
+  storage: {
+    type: prompt("SSD or HDD"),
+    volume: +prompt("How many Gb you need?"),
+  },
+};
+
+clientsCar.owner = clientCard.name;
+
+clientCard.car = clientsCar.brand;
+clientCard.notebook = noteOfDream.brand;
+
+console.log(clientsCar);
+console.log(clientCard);
+console.log(noteOfDream);
 
-// let noteOfDream = {
-//   brand: prompt("what brand of laptop would you like?"),
-//   model: prompt("select laptop model "),
-//   CPU: prompt("select the CPU"),
-//   GPU: prompt("choose graphics: built-in or discrete "),
-//   GPU_memory: +prompt(
-//     "if you chose discrete graphics, select the amount of video memory you want "
-//   ),
-//   display: {
-//     width: +prompt("enter width of resolution"),
-//     height: +prompt("enter height of resolution"),
-//     refresh_rate: prompt("What level of screen refresh is right for you?"),
-//   },
-//   storage: {
-//     type: prompt("SSD or HDD"),
-//     volume: +prompt("How many Gb you need?"),
-//   },
-// };
 // imperative array fill 3----------------------------------------------------------------------------------;
 
 // let foodList = [
@@ -189,11 +197,7 @@ console.log(body.subTags[0].subTags[3].attrs.id);
 
 // empty loop-----------------------------------------------------------------------------------------------;
 
-// for (; userSays !== null; ) {
-//   userSays = prompt("Type anything");
-// }
-
-// console.log(userSays);
+while (prompt() === null);
 
 // progression sum------------------------------------------------------------------------------------------;
 
@@ -204,12 +208,12 @@ console.log(body.subTags[0].subTags[3].attrs.id);
 
 // alert(fn(7));
 
-// chess one line-------------------------------------------------------------------------------------------;
+// chess online-------------------------------------------------------------------------------------------;
 
 // let str = "";
 
 // for (i = 0; i <= 10; i++) {
-//   str += "" + "#";
+//   str += " " + "#";
 // }
 
 // console.log(str);
@@ -220,7 +224,7 @@ console.log(body.subTags[0].subTags[3].attrs.id);
 // for (j = 0; j <= 9; j++) {
 //   numbers += "\n";
 //   for (i = 0; i <= 9; i++) {
-//     numbers += "" + i;
+//     numbers += i;
 //   }
 // }
 // console.log(numbers);
@@ -254,7 +258,7 @@ console.log(cubes);
 // multiply table-------------------------------------------------------------------------------------------;
 
 let multiplication = Array(11);
-for (let i = 1; i < 11; i++) {
+for (let i = 0; i < 11; i++) {
   multiplication[i] = [...Array(11)].map((_, j) => i * j);
 }
 
@@ -304,11 +308,10 @@ document.write("<table>");
 let lines = (line = 6),
   a = ".",
   b = "#";
-for (; line-- > 0; )
+for (; line-- > 0; ) {
   console.log(
     Array(line + 1).join(a) +
       Array(2 * (lines - line)).join(b) +
       Array(line + 1).join(a)
   );
-
-// Задание на черный пояс: Электронная гадалка--------------------------------------------------------------;
+}

+ 390 - 0
Homework_16/associative_arrays.js

@@ -0,0 +1,390 @@
+// 3 persons------------------------------------------------------------------------------------------------------------------------------------//
+
+// let a = {
+//   name: "Alexandra",
+//   surname: "Olefirenko",
+
+// };
+
+// let b = {
+//   name: "Platon",
+//   surname: "Plokhenko",
+
+// };
+
+// let c = {
+//   name: "Sofia",
+//   surname: "Sternenko",
+
+// };
+
+// different fields---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+// let a = {
+//   name: "Alexandra",
+//   surname: "Olefirenko",
+//   sex: "female",
+//   age: 21,
+// };
+
+// let b = {
+//   name: "Platon",
+//   surname: "Plokhenko",
+//   education: "Bachelor degree",
+//   age: 18,
+// };
+
+// let c = {
+//   name: "Sofia",
+//   surname: "Sternenko",
+//   fathername: "Vyktoryvna",
+//   age: 27,
+// };
+
+// fields check---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+let a = {
+  name: "Alexandra",
+  surname: "Olefirenko",
+  sex: "female",
+  age: 21,
+};
+
+let b = {
+  name: "Platon",
+  surname: "Plokhenko",
+  education: "Bachelor degree",
+  age: 18,
+};
+
+let c = {
+  name: "Sofia",
+  surname: "Sternenko",
+  fathername: "Vyktoryvna",
+  age: 27,
+};
+
+if (Object.keys(a).includes("age", "sex")) {
+  console.log(a.sex, a.age);
+} else {
+  console.log("Not here");
+}
+
+if (Object.keys(b).includes("age", "education")) {
+  console.log(b.sex, b.education);
+} else {
+  console.log("Not here");
+}
+
+if (Object.keys(c).includes("fathername", "age")) {
+  console.log(c.fathername, c.age);
+} else {
+  console.log("Not here");
+}
+
+// array of persons---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+let persons = [
+  (a = {
+    name: "Alexandra",
+    surname: "Olefirenko",
+    sex: "F",
+    age: 21,
+  }),
+  (b = {
+    name: "Platon",
+    surname: "Plokhenko",
+    sex: "M",
+    age: 18,
+    education: "Bachelor degree",
+  }),
+  (c = {
+    name: "Sofia",
+    surname: "Sternenko",
+    fathername: "Vyktoryvna",
+    sex: "F",
+    age: 27,
+    region: "Kyiv",
+    phoneNumber: "0731232323",
+  }),
+];
+
+// loop of persons-----------------------------------------------------------------------------------------------------------------------------------------------------------;
+
+for (i = 0; i < persons.length; i++) {
+  console.log(persons[i]);
+}
+
+// loop of name and surname---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+for (let i = 0; i < persons.length; i++) {
+  if (
+    typeof persons[i].name === "string" &&
+    typeof persons[i].surname === "string"
+  ) {
+    for (key in persons[i]) {
+    }
+    console.log(
+      "name: " +
+        " " +
+        persons[i].name +
+        "," +
+        " " +
+        "surname: " +
+        " " +
+        persons[i].surname
+    );
+  } else {
+    alert("error");
+  }
+}
+
+// loop of loop of values---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+for (i = 0; i <= persons.length; i++) {
+  for (let key in persons[i]) {
+    console.log(key + ": " + persons[i][key]);
+  }
+}
+// fullName---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+for (let i = 0; i <= persons.length; i++) {
+  for (let key in persons[i]) {
+    if ("fathername" in persons[i]) {
+      console.log(
+        (persons[i].fullName =
+          persons[i].surname +
+          " " +
+          persons[i].name +
+          " " +
+          persons[i].fathername)
+      );
+    } else {
+      console.log(
+        (persons[i].fullName = persons[i].surname + " " + persons[i].name)
+      );
+    }
+  }
+}
+// serialize---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+JSON.stringify(persons);
+
+// deserialize---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+let d = JSON.parse('{"name": "Taras", "surname": "Shevchenko"}');
+persons.push(d);
+
+// HTML----------------------------------------------------------------------------------------------------------------------------------------------------------;
+document.write("</table>");
+document.write(
+  '<table style = "border-collapse: collapse", "border: 1px solid black; ">'
+);
+document.write("<tr>");
+
+for (key in persons[0]) {
+  document.write('<th style = "border: 1px solid black;">' + key + "</th>");
+}
+document.write("</tr>");
+for (let i = 0; i < persons.length; i++) {
+  document.write("<tr>");
+  for (value in persons[i]) {
+    document.write(
+      '<td style = "border: 1px solid black;">' + persons[i][value] + "</td>"
+    );
+  }
+  document.write("</tr>");
+}
+document.write("</table>");
+
+// HTML optional fields---------------------------------------------------------------------------------------------------------------------------------------------------;
+{
+  let headers = persons
+    .reduce((a, b) => a.concat(Object.keys(b)), [])
+    .filter((v, i, s) => s.indexOf(v) === i);
+  str =
+    `<table style = "border: 1px solid black; border-collapse: collapse;"><tr>${headers
+      .map(
+        (e) =>
+          `<th style = "border: 1px solid black; border-collapse: collapse;">${e}</th>`
+      )
+      .join("\n")}</tr>` +
+    persons
+      .map(
+        (e) =>
+          `<tr>${headers
+            .map(
+              (e1) =>
+                `<td style = "border: 1px solid black; border-collapse: collapse;">${
+                  e[e1] ? e[e1] : "-"
+                }</td>`
+            )
+            .join("\n")}</tr>`
+      )
+      .join("\n") +
+    `</table>`;
+
+  document.write(str);
+}
+// HTML tr color---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+{
+  let headers = persons
+    .reduce((a, b) => a.concat(Object.keys(b)), [])
+    .filter((v, i, s) => s.indexOf(v) === i);
+  str =
+    `<table style = "border: 1px solid black; border-collapse: collapse;"><tr style = "background-color: #ffff00;" >${headers
+      .map(
+        (e) =>
+          `<th style = "border: 1px solid black; border-collapse: collapse;">${e}</th>`
+      )
+      .join("\n")}</tr>` +
+    persons
+      .map(
+        (e) =>
+          `<tr style = "background-color: lightgreen;">${headers
+            .map(
+              (e1) =>
+                `<td style = "border: 1px solid black; border-collapse: collapse;">${
+                  e[e1] ? e[e1] : "-"
+                }</td>`
+            )
+            .join("\n")}</tr>`
+      )
+      .join("\n") +
+    `</table>`;
+
+  document.write(str);
+}
+// HTML th optional---------------------------------------------------------------------------------------------------------------------------------------------------;
+// Задание на синий пояс.---------------------------------------------------------------------------------------------------------------------------------------------------;
+// HTML constructor---------------------------------------------------------------------------------------------------------------------------------------------------------;
+let body = {
+  tagName: "body",
+  subTags: [
+    {
+      tagName: "div",
+      subTags: [
+        {
+          tagName: "span",
+          text: "Enter a data please:",
+        },
+        {
+          tagName: "br",
+        },
+        {
+          tagName: "input",
+          attrs: {
+            type: "text",
+            id: "name",
+          },
+        },
+        {
+          tagName: "input",
+          attrs: {
+            type: "text",
+            id: "surname",
+          },
+        },
+      ],
+    },
+    {
+      tagName: "div",
+      subTags: [
+        {
+          tagName: "button",
+          text: "OK",
+          attrs: {
+            id: "ok",
+          },
+        },
+        {
+          tagName: "button",
+          text: "cancel",
+          attrs: {
+            id: "cancel",
+          },
+        },
+      ],
+    },
+  ],
+};
+
+function createElem(tagName, attrs, text) {
+  var elem = document.createElement(tagName);
+  if (attrs) for (var name in attrs) elem.setAttribute(name, attrs[name]);
+  if (text) elem.textContent = text;
+  return elem;
+}
+
+function walker(tree) {
+  var tagName = tree.tagName,
+    attrs = tree.attrs,
+    text = tree.text,
+    elem = createElem(tagName, attrs, text);
+  if (tree.subTags)
+    tree.subTags.forEach(function (el) {
+      el = walker(el);
+      elem.appendChild(el);
+    });
+  return elem;
+}
+var table = walker(body);
+document.body.appendChild(table);
+
+// destruct array---------------------------------------------------------------------------------------------------------------------------------------------------;
+{
+  let arr = [1, 2, 3, 4, 5, "a", "b", "c"];
+
+  let evenArray = [];
+  let oddArray = [];
+  let lettersFromArr = [];
+  for (let i = 0; i < arr.length; i++) {
+    if (typeof arr[i] === "number") {
+      if (arr[i] % 2 === 0) {
+        evenArray.push(arr[i]);
+      } else {
+        oddArray.push(arr[i]);
+      }
+    } else {
+      lettersFromArr.push(arr[i]);
+    }
+  }
+
+  let [even1, even2] = evenArray;
+  let [odd1, odd2, odd3] = oddArray;
+}
+
+// destruct string---------------------------------------------------------------------------------------------------------------------------------------------------;
+let arr1 = [1, "abc"];
+
+let [number, [s1, s2, s3]] = arr1;
+
+console.log(number);
+console.log(s1);
+console.log(s2);
+console.log(s3);
+
+// destruct 2---------------------------------------------------------------------------------------------------------------------------------------------------;
+let obj = {
+  name: "Ivan",
+  surname: "Petrov",
+  children: [{ name: "Maria" }, { name: "Nikolay" }],
+};
+
+let {
+  children: [{ name: name1 }, { name: name2 }],
+} = obj;
+
+console.log(name1);
+console.log(name2);
+// destruct 3---------------------------------------------------------------------------------------------------------------------------------------------------;
+{
+  let arr = [1, 2, 3, 4, 5, 6, 7, 10];
+
+  let { 0: a, 1: b, length } = arr;
+
+  console.log(a);
+  console.log(b);
+  console.log(length);
+}

+ 15 - 0
Homework_16/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>
+    <script src="/associative_arrays.js"></script>
+</body>
+
+</html>

+ 15 - 0
Homework_17/func.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>
+    <script src="/functions.js"></script>
+</body>
+
+</html>

+ 27 - 0
Homework_17/functions.js

@@ -0,0 +1,27 @@
+// ДЗ: Функции и области видимости
+
+// a---------------------------------------------------------------------------------------------------------;
+function a() {
+  alert();
+}
+
+a("Hello");
+
+// cube------------------------------------------------------------------------------------------------------;
+
+function cube(a) {}
+
+// avg2------------------------------------------------------------------------------------------------------;
+
+function avg2(a, b) {
+  return (a + b) / 2;
+}
+avg2(1, 2);
+avg2(10, 5);
+
+// sum3------------------------------------------------------------------------------------------------------;
+// intRandom-------------------------------------------------------------------------------------------------;
+// greetAll--------------------------------------------------------------------------------------------------;
+// sum-------------------------------------------------------------------------------------------------------;
+// Union-----------------------------------------------------------------------------------------------------;
+// Union declarative-----------------------------------------------------------------------------------------;