Browse Source

HW 13 rewrite

OleksiiL 1 year ago
parent
commit
7250485081
5 changed files with 277 additions and 17 deletions
  1. 24 17
      Homework_13/main.js
  2. 196 0
      Homework_16/associative_arrays.js
  3. 15 0
      Homework_16/index.html
  4. 15 0
      Homework_17/func.html
  5. 27 0
      Homework_17/functions.js

+ 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`
 );

+ 196 - 0
Homework_16/associative_arrays.js

@@ -0,0 +1,196 @@
+// 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,
+// };
+
+// 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",
+    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---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+// fullName---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+// for (var i = 0; i < persons.length; i++) {
+//   for (var key in persons[i]) {
+//     persons[i].fullName = persons[i].fullName =
+//       persons[i].name + " " + persons[i].surname;
+//   }
+// }
+// serialize---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+// JSON.stringify(persons);
+
+// deserialize---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+// JSON.parse('{"name: Taras, surname: Shevchenko"}');
+
+// 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---------------------------------------------------------------------------------------------------------------------------------------------------;
+// HTML tr color---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+document.write("<table>");
+document.write('<tr style="color: red;">');
+
+for (key in persons[0]) {
+  document.write("<th>" + key + "</th>");
+}
+document.write("</tr>");
+for (i = 0; i < persons.length; i++) {
+  document.write("<tr >");
+  for (value in persons[i]) {
+    document.write("<td>" + persons[i][value] + "</td>");
+  }
+  document.write("</tr>");
+}
+document.write("</table>");
+
+// HTML th optional---------------------------------------------------------------------------------------------------------------------------------------------------;
+// Задание на синий пояс.---------------------------------------------------------------------------------------------------------------------------------------------------;
+// destruct array---------------------------------------------------------------------------------------------------------------------------------------------------;
+
+// destruct string---------------------------------------------------------------------------------------------------------------------------------------------------;
+let arr1 = [1, "abc"];
+// destruct 2---------------------------------------------------------------------------------------------------------------------------------------------------;
+let obj = {
+  name: "Ivan",
+  surname: "Petrov",
+  children: [{ name: "Maria" }, { name: "Nikolay" }],
+};
+
+// destruct 3---------------------------------------------------------------------------------------------------------------------------------------------------;
+let arr = [1, 2, 3, 4, 5, 6, 7, 10];
+// Задание на черный пояс---------------------------------------------------------------------------------------------------------------------------------------------------;

+ 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-----------------------------------------------------------------------------------------;