|
@@ -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);
|