|
@@ -0,0 +1,314 @@
|
|
|
+// ДЗ: Вложенные декларативные структуры и код в них. Отображение циклических и древовидных структур. Циклы.
|
|
|
+
|
|
|
+// html tree------------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+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",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+};
|
|
|
+
|
|
|
+// Текст другої кнопки
|
|
|
+console.log(body.subTags[1].subTags[1].text);
|
|
|
+
|
|
|
+// ID другого input
|
|
|
+console.log(body.subTags[0].subTags[3].attrs.id);
|
|
|
+
|
|
|
+// declarative fields--------------------------------------------------------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// 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?"),
|
|
|
+// },
|
|
|
+// };
|
|
|
+
|
|
|
+// 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 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 = [
|
|
|
+// prompt("Enter 1 product in list"),
|
|
|
+// prompt("Enter 1 product in list"),
|
|
|
+// prompt("Enter 1 product in list"),
|
|
|
+// ];
|
|
|
+
|
|
|
+// while confirm--------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// let userConfirm;
|
|
|
+
|
|
|
+// do {
|
|
|
+// userConfirm = confirm("Do you want buy anything?");
|
|
|
+// console.log(userConfirm);
|
|
|
+// } while (userConfirm == false);
|
|
|
+
|
|
|
+// array fill-----------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// let productsList = [];
|
|
|
+
|
|
|
+// do {
|
|
|
+// userChoice = prompt("What you must buy in shop?");
|
|
|
+// productsList.push(userChoice);
|
|
|
+// console.log(productsList);
|
|
|
+// } while (userChoice !== null);
|
|
|
+
|
|
|
+// array fill nopush----------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// let productsList = [];
|
|
|
+// let userChoice;
|
|
|
+
|
|
|
+// for (i = 0; userChoice !== null; i++) {
|
|
|
+// userChoice = prompt("What you must buy in shop?");
|
|
|
+// productsList[i] = userChoice;
|
|
|
+// console.log(productsList);
|
|
|
+// }
|
|
|
+
|
|
|
+// infinite probability-------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// for (let i = 0; true; i++)
|
|
|
+// if (Math.random() > 0.9) {
|
|
|
+// alert(++i);
|
|
|
+
|
|
|
+// break;
|
|
|
+// }
|
|
|
+
|
|
|
+// empty loop-----------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// for (; userSays !== null; ) {
|
|
|
+// userSays = prompt("Type anything");
|
|
|
+// }
|
|
|
+
|
|
|
+// console.log(userSays);
|
|
|
+
|
|
|
+// progression sum------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// function fn(n) {
|
|
|
+// for (let s = (i = 1); i < n; s += i += 3) {}
|
|
|
+// return s;
|
|
|
+// }
|
|
|
+
|
|
|
+// alert(fn(7));
|
|
|
+
|
|
|
+// chess one line-------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// let str = "";
|
|
|
+
|
|
|
+// for (i = 0; i <= 10; i++) {
|
|
|
+// str += "" + "#";
|
|
|
+// }
|
|
|
+
|
|
|
+// console.log(str);
|
|
|
+
|
|
|
+// numbers--------------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// let numbers = "";
|
|
|
+// for (j = 0; j <= 9; j++) {
|
|
|
+// numbers += "\n";
|
|
|
+// for (i = 0; i <= 9; i++) {
|
|
|
+// numbers += "" + i;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// console.log(numbers);
|
|
|
+
|
|
|
+// chess----------------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+// const dot = ".";
|
|
|
+// const tag = "#";
|
|
|
+// let res = "";
|
|
|
+
|
|
|
+// for (let i = 0; i < 10; i++) {
|
|
|
+// let str = "";
|
|
|
+// for (let j = 0; j < 12; j++) {
|
|
|
+// str += (i + j) & 1 ? tag : dot;
|
|
|
+// }
|
|
|
+// res += str + "\n";
|
|
|
+// }
|
|
|
+
|
|
|
+// console.log(res);
|
|
|
+
|
|
|
+// cubes----------------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+let cubes = [];
|
|
|
+let n = 100;
|
|
|
+
|
|
|
+for (i = 0; i < n; i++) {
|
|
|
+ cubes.push(i ** 3);
|
|
|
+}
|
|
|
+console.log(cubes);
|
|
|
+
|
|
|
+// multiply table-------------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+let multiplication = Array(11);
|
|
|
+for (let i = 1; i < 11; i++) {
|
|
|
+ multiplication[i] = [...Array(11)].map((_, j) => i * j);
|
|
|
+}
|
|
|
+
|
|
|
+console.log(multiplication);
|
|
|
+
|
|
|
+// matrix to html table-------------------------------------------------------------------------------------;
|
|
|
+
|
|
|
+document.write("<style>td, caption {font-family: arial}</style>");
|
|
|
+
|
|
|
+document.write('<table align="center" bgcolor="7ffa92" ');
|
|
|
+document.write('cellspacing="0" cellpadding="4" ');
|
|
|
+document.write('border="2" style="border-collapse: collapse">');
|
|
|
+
|
|
|
+document.write(
|
|
|
+ "<caption><p><b>Multiplication table in decimal system</caption></b>"
|
|
|
+);
|
|
|
+
|
|
|
+for (let row = 0; row <= 10; row++) {
|
|
|
+ document.write("<tr>");
|
|
|
+ for (let col = 0; col <= 10; col++) {
|
|
|
+ if (row == 0 || col == 0) {
|
|
|
+ codeTD = '<td align="center" width="4%" bgcolor="b1c4b4">';
|
|
|
+ if (row == col) {
|
|
|
+ codeContent = "<b>&#" + "215;</b>";
|
|
|
+ } else if (row == 0) {
|
|
|
+ codeContent = "<b>" + col + "</b>";
|
|
|
+ } else if (col == 0) {
|
|
|
+ codeContent = "<b>" + row + "</b>";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ codeTD = '<td align="center">';
|
|
|
+ if (row == col) {
|
|
|
+ codeContent = "<b>" + row * col + "</b>";
|
|
|
+ } else {
|
|
|
+ codeContent = row * col;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ document.write(codeTD + codeContent + "</td>");
|
|
|
+ }
|
|
|
+ document.write("</tr>");
|
|
|
+}
|
|
|
+
|
|
|
+document.write("<table>");
|
|
|
+
|
|
|
+// Задание на синий пояс: Треугольник-----------------------------------------------------------------------;
|
|
|
+
|
|
|
+let lines = (line = 6),
|
|
|
+ a = ".",
|
|
|
+ b = "#";
|
|
|
+for (; line-- > 0; )
|
|
|
+ console.log(
|
|
|
+ Array(line + 1).join(a) +
|
|
|
+ Array(2 * (lines - line)).join(b) +
|
|
|
+ Array(line + 1).join(a)
|
|
|
+ );
|
|
|
+
|
|
|
+// Задание на черный пояс: Электронная гадалка--------------------------------------------------------------;
|