Selaa lähdekoodia

Third commit - loops and arrays

Bonyant 2 vuotta sitten
vanhempi
commit
a82d5e556d
3 muutettua tiedostoa jossa 431 lisäystä ja 0 poistoa
  1. 12 0
      03/index.html
  2. 367 0
      03/script.js
  3. 52 0
      03/styles.css

+ 12 - 0
03/index.html

@@ -0,0 +1,12 @@
+<!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>JavaScript Arrays</title>
+    <script src="script.js"></script>
+    <link rel="stylesheet" href="styles.css" />
+  </head>
+  <body></body>
+</html>

+ 367 - 0
03/script.js

@@ -0,0 +1,367 @@
+// ДЗ: Вложенные декларативные структуры и код в них. Отображение циклических и древовидных структур. Циклы.
+
+// html tree
+
+// <body>
+// <div>
+//     <span>Enter a data please:</span><br/>
+//     <input type='text' id='name'>
+//     <input type='text' id='surname'>
+// </div>
+// <div>
+//     <button id='ok'>OK</button>
+//     <button id='cancel'>Cancel</button>
+// </div>
+// </body>
+
+// const structure = {
+//   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",
+//             attrs: {
+//               id: "ok",
+//             },
+//             text: "OK",
+//           },
+//           {
+//             tagName: "button",
+//             attrs: {
+//               id: "cancel",
+//             },
+//             text: "Cancel",
+//           },
+//         ],
+//       },
+//     ],
+//   },
+// };
+
+// alert(
+//   `Значения текста во второй кнопке: ${structure.body.subTags[1].subTags[1].text}.\nЗначение атрибута id во втором input: ${structure.body.subTags[0].subTags[3].attrs.id}`
+// );
+
+// declarative fields
+
+// const notebook = {
+//   brand: prompt("Введите брэнд ноутбука").trim(),
+//   type: prompt("Введите тип ноутбука").trim(),
+//   model: prompt("Введите модель ноутбука").trim(),
+//   ram: +prompt("Введите количество памяти ноутбука").trim(),
+//   size: prompt("Введите размер в дюймах ноутбука").trim(),
+//   weight: +prompt("Введите вес ноутбука").trim(),
+//   resolution: {
+//     width: +prompt("Введите ширину в пикселях ноутбука").trim(),
+//     height: +prompt("Введите высоту в пикселях ноутбука").trim(),
+//   },
+// };
+
+// const phone = {
+//   brand: prompt("Введите брэнд телефона").trim(),
+//   model: prompt("Введите модель телефона").trim(),
+//   ram: +prompt("Введите память телефона").trim(),
+//   color: prompt("Введите цвет телефона").trim(),
+// };
+
+// const person = {
+//   name: prompt("Введите имя человека").trim(),
+//   surname: prompt("Введите фамилию человека").trim(),
+//   married: confirm("Этот человек женат(замужем)?"),
+// };
+
+// let strObj = "<table border='1'>";
+// for (let [key, value] of Object.entries(person)) {
+//   strObj += "<tr>";
+//   strObj += "<td>";
+//   strObj += key[0].toUpperCase() + key.slice(1);
+//   strObj += "</td>";
+//   strObj += "<td>";
+//   strObj +=
+//     typeof value === "string"
+//       ? value[0].toUpperCase() + value.slice(1)
+//       : typeof value === "object"
+//       ? Object.values(value)
+//       : value === true
+//       ? (value = "Yes")
+//       : value === false
+//       ? (value = "No")
+//       : value;
+//   strObj += "</td>";
+//   strObj += "</tr>";
+// }
+// strObj += "</table>";
+// document.write(strObj);
+
+// object links
+// const info = {
+//   person: {
+//     name: prompt("Введите имя человека").trim() || "John",
+//     surname: prompt("Введите фамилию человека").trim() || "Johnson",
+//     married: confirm("Этот человек женат(замужем)?") || true,
+//   },
+//   notebook: {
+//     brand: prompt("Введите брэнд ноутбука").trim() || "Dell",
+//     type: prompt("Введите тип ноутбука").trim() || "Latitude",
+//     model: prompt("Введите модель ноутбука").trim() || "E5450",
+//     ram: +prompt("Введите количество памяти ноутбука").trim() || 4,
+//     size: prompt("Введите размер в дюймах ноутбука").trim() || "15",
+//     weight: +prompt("Введите вес ноутбука").trim() || 2,
+//     resolution: {
+//       width: +prompt("Введите ширину в пикселях ноутбука").trim() || 1920,
+//       height: +prompt("Введите высоту в пикселях ноутбука").trim() || 1080,
+//     },
+//   },
+//   phone: {
+//     brand: prompt("Введите брэнд телефона").trim() || "Samsung",
+//     model: prompt("Введите модель телефона").trim() || "A50",
+//     ram: +prompt("Введите память телефона").trim() || 4,
+//     color: prompt("Введите цвет телефона").trim() || "Blue",
+//   },
+// };
+// let strObj;
+// strObj = "<table border='1' class='personInfo'>";
+// strObj += "<caption>Person Info</caption>";
+// for (let [key, value] of Object.entries(info.person)) {
+//   strObj += "<tr>";
+//   strObj += "<td>";
+//   strObj += key[0].toUpperCase() + key.slice(1);
+//   strObj += "</td>";
+//   strObj += "<td>";
+//   strObj +=
+//     typeof value === "string"
+//       ? value[0].toUpperCase() + value.slice(1)
+//       : typeof value === "object"
+//       ? Object.values(value)
+//       : value === true
+//       ? (value = "Yes")
+//       : value === false
+//       ? (value = "No")
+//       : value;
+//   strObj += "</td>";
+//   strObj += "</tr>";
+// }
+// strObj += "</table>";
+// info.person.notebook = `${info.notebook.brand} ${info.notebook.type} ${info.notebook.model}`;
+// info.person.phone = `${info.phone.brand} ${info.phone.model}` || "None";
+// document.write(strObj);
+
+// strObj = "<table border='1' class='notebookInfo'>";
+// strObj += "<caption>Notebook Info</caption>";
+// for (let [key, value] of Object.entries(info.notebook)) {
+//   strObj += "<tr>";
+//   strObj += "<td>";
+//   strObj += key[0].toUpperCase() + key.slice(1);
+//   strObj += "</td>";
+//   strObj += "<td>";
+//   strObj +=
+//     typeof value === "string"
+//       ? value[0].toUpperCase() + value.slice(1)
+//       : typeof value === "object"
+//       ? Object.values(value)
+//       : value === true
+//       ? (value = "Yes")
+//       : value === false
+//       ? (value = "No")
+//       : value;
+//   strObj += "</td>";
+//   strObj += "</tr>";
+// }
+// strObj += "</table>";
+// info.notebook.owner = `${info.person.name} ${info.person.surname}` || "None";
+// document.write(strObj);
+
+// strObj = "<table border='1' class='phoneInfo'>";
+// strObj += "<caption>Phone Info</caption>";
+// for (let [key, value] of Object.entries(info.phone)) {
+//   strObj += "<tr>";
+//   strObj += "<td>";
+//   strObj += key[0].toUpperCase() + key.slice(1);
+//   strObj += "</td>";
+//   strObj += "<td>";
+//   strObj +=
+//     typeof value === "string"
+//       ? value[0].toUpperCase() + value.slice(1)
+//       : typeof value === "object"
+//       ? Object.values(value)
+//       : value === true
+//       ? (value = "Yes")
+//       : value === false
+//       ? (value = "No")
+//       : value;
+//   strObj += "</td>";
+//   strObj += "</tr>";
+// }
+// strObj += "</table>";
+// info.phone.owner = `${info.person.name} ${info.person.surname}` || "None";
+// document.write(strObj);
+
+// imperative array fill 3
+
+// const impArray = [];
+// impArray[0] = prompt("Введите 1 элемент массива");
+// impArray[1] = prompt("Введите 2 элемент массива");
+// impArray[2] = prompt("Введите 3 элемент массива");
+// alert(`Array: [${impArray}]`);
+
+// while confirm
+
+// while (!confirm("Отмена - продолжить while, ОК - отменить"));
+
+// array fill && array fill nopush
+
+// const arrayFill = [];
+// let arrayLen = 1;
+// for (let i = 0; i < arrayLen; i++) {
+//   arrayFill[i] = prompt(
+//     "Введите элемент для добавления его в массив | Отмена или пустой ввод - остановить добавление"
+//   );
+//   if (!!arrayFill[i] === false) {
+//     arrayFill.splice(i, 1);
+//     break;
+//   }
+//   arrayLen++;
+// }
+// alert(`Array: [${arrayFill}]`);
+
+// infinite probability
+
+// let itt = 0;
+// while (true) {
+//   itt++;
+//   let random = Math.random();
+//   console.log(`Number ${itt}: ${random}`);
+//   if (random > 0.9) {
+//     break;
+//   }
+// }
+// alert(`Itterations: ${itt}`);
+
+// empty loop
+// while (prompt("Остановить?") === null ? true : false);
+
+// progression sum
+// let n = 20;
+// let sum = 0;
+// for (let i = 1; i <= n; i += 3) {
+//   sum += i;
+// }
+// alert(`Сумма арифметической прогрессии от 1 до ${n} с шагом 3: ${sum}`);
+
+// chess one line
+// let lenStr = +prompt("Введите длину строки").trim();
+// let str = " ";
+// console.log(lenStr);
+// if (!Number.isNaN(lenStr)) {
+//   for (let i = 0; i < lenStr; i++) {
+//     str += "#";
+//   }
+//   str += " ";
+//   alert(`Result: "${str}"`);
+// } else {
+//   alert("Вы ввели некорректную длину строки");
+// }
+
+// numbers
+
+// let str = "";
+// for (let col = 0; col < 10; col++) {
+//   for (let row = 0; row < 10; row++) {
+//     str += row;
+//   }
+//   str += "\n";
+// }
+// alert(str);
+
+// chess
+
+// let chessLen = 10;
+// let chess = "";
+// for (let col = 0; col < chessLen; col++) {
+//   for (let row = 0; row < chessLen / 2 + 1; row++) {
+//     col % 2 === 0 ? (chess += ".#") : (chess += "#.");
+//   }
+//   chess += "\n";
+// }
+// alert(chess);
+
+// cubes
+
+// const cubes = [];
+// const arrayLen = 10;
+// for (let i = 0; i < arrayLen; i++) {
+//   cubes.push(i ** 3);
+// }
+// alert(`Array: [${cubes}]`);
+
+// multiply table
+
+// let tableLen = 10;
+// const table = [];
+// for (let i = 0; i < tableLen; i++) {
+//   table.push([]);
+//   for (let j = 0; j < tableLen; j++) {
+//     table[i][j] = i * j;
+//   }
+// }
+// console.log(table);
+
+// matrix to html table
+
+// let str = "<table border='1'>";
+// for (let rowIndex = 0; rowIndex < 10; rowIndex++) {
+//   str += "<tr>";
+//   for (let tdIndex = 0; tdIndex < 10; tdIndex++) {
+//     str += "<td>";
+//     str += tdIndex * rowIndex;
+//     str += "</td>";
+//   }
+//   str += "</tr>";
+// }
+// str += "</table>";
+// document.write(str);
+
+// Задание на синий пояс: Треугольник
+
+// const rectLen = 11;
+// let flag = 1;
+// let rect = "";
+// for (let i = 0; i < rectLen / 2; i++) {
+//   for (let j = 0; j < rectLen / 4 - 2; j++) {
+//     rect += ".".repeat((rectLen - flag) / 2);
+//     rect += "#".repeat(flag);
+//     rect += ".".repeat((rectLen - flag) / 2);
+//     rect += "\n";
+//   }
+//   flag += 2;
+// }
+// console.log(rect);

+ 52 - 0
03/styles.css

@@ -0,0 +1,52 @@
+body {
+  background-color: #230b36;
+  font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
+  display: flex;
+  justify-content: center;
+}
+
+.personInfo,
+.phoneInfo,
+.notebookInfo {
+  font-size: 16px;
+  width: 640px;
+  text-align: left;
+  border-collapse: collapse;
+  background: #252f48;
+  margin: 10px;
+}
+.personInfo,
+.phoneInfo,
+.notebookInfo,
+th {
+  color: #edb749;
+  border-bottom: 1px solid #37b5a5;
+  padding: 12px 17px;
+}
+.personInfo,
+.phoneInfo,
+.notebookInfo,
+td {
+  color: #cad4d6;
+  border-bottom: 1px solid #37b5a5;
+  border-right: 1px solid #37b5a5;
+  padding: 7px 17px;
+}
+.personInfo,
+.phoneInfo,
+.notebookInfo,
+tr:last-child td {
+  border-bottom: none;
+}
+.personInfo,
+.phoneInfo,
+.notebookInfo,
+td:last-child {
+  border-right: none;
+}
+.personInfo,
+.phoneInfo,
+.notebookInfo,
+tr:hover td {
+  text-decoration: underline;
+}