tree_structure.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. // ДЗ: Вложенные декларативные структуры и код в них. Отображение циклических и древовидных структур. Циклы.
  2. // html tree------------------------------------------------------------------------------------------------;
  3. let body = {
  4. tagName: "body",
  5. subTags: [
  6. {
  7. tagName: "div",
  8. subTags: [
  9. {
  10. tagName: "span",
  11. text: "Enter a data please:",
  12. },
  13. {
  14. tagName: "br",
  15. },
  16. {
  17. tagName: "input",
  18. attrs: {
  19. type: "text",
  20. id: "name",
  21. },
  22. },
  23. {
  24. tagName: "input",
  25. attrs: {
  26. type: "text",
  27. id: "surname",
  28. },
  29. },
  30. ],
  31. },
  32. {
  33. tagName: "div",
  34. subTags: [
  35. {
  36. tagName: "button",
  37. text: "OK",
  38. attrs: {
  39. id: "ok",
  40. },
  41. },
  42. {
  43. tagName: "button",
  44. text: "cancel",
  45. attrs: {
  46. id: "cancel",
  47. },
  48. },
  49. ],
  50. },
  51. ],
  52. };
  53. // Текст другої кнопки
  54. console.log(body.subTags[1].subTags[1].text);
  55. // ID другого input
  56. console.log(body.subTags[0].subTags[3].attrs.id);
  57. // declarative fields--------------------------------------------------------------------------------------------------------------------------------------------;
  58. // let clientsCar = {
  59. // brand: prompt("Enter a brand car"),
  60. // model: prompt("Enter a model of car"),
  61. // volume: +prompt("choose volume of your future car"),
  62. // color: prompt("What color you wish?"),
  63. // HP: +prompt("Enter horse power what you need"),
  64. // };
  65. // let clientCard = {
  66. // name: prompt("Enter your name, please"),
  67. // surname: prompt("Enter your surname, please"),
  68. // age: +prompt("Enter your age, please"),
  69. // education: prompt(
  70. // "enter your educational level (higher education, secondary education, etc."
  71. // ),
  72. // gender: prompt("choose your gender: man, woman"),
  73. // sallery: +prompt("what is your annual income?"),
  74. // };
  75. // let noteOfDream = {
  76. // brand: prompt("what brand of laptop would you like?"),
  77. // model: prompt("select laptop model "),
  78. // CPU: prompt("select the CPU"),
  79. // GPU: prompt("choose graphics: built-in or discrete "),
  80. // GPU_memory: +prompt(
  81. // "if you chose discrete graphics, select the amount of video memory you want "
  82. // ),
  83. // display: {
  84. // width: +prompt("enter width of resolution"),
  85. // height: +prompt("enter height of resolution"),
  86. // refresh_rate: prompt("What level of screen refresh is right for you?"),
  87. // },
  88. // storage: {
  89. // type: prompt("SSD or HDD"),
  90. // volume: +prompt("How many Gb you need?"),
  91. // },
  92. // };
  93. // object links---------------------------------------------------------------------------------------------;
  94. // let clientsCar = {
  95. // brand: prompt("Enter a brand car"),
  96. // model: prompt("Enter a model of car"),
  97. // volume: +prompt("choose volume of your future car"),
  98. // color: prompt("What color you wish?"),
  99. // HP: +prompt("Enter horse power what you need"),
  100. // owner: clientCard.name,
  101. // };
  102. // let clientCard = {
  103. // name: prompt("Enter your name, please"),
  104. // surname: prompt("Enter your surname, please"),
  105. // age: +prompt("Enter your age, please"),
  106. // education: prompt(
  107. // "enter your educational level (higher education, secondary education, etc."
  108. // ),
  109. // gender: prompt("choose your gender: man, woman"),
  110. // sallery: +prompt("what is your annual income?"),
  111. // car: clientsCar.brand,
  112. // notebook: noteOfDream.brand,
  113. // };
  114. // let noteOfDream = {
  115. // brand: prompt("what brand of laptop would you like?"),
  116. // model: prompt("select laptop model "),
  117. // CPU: prompt("select the CPU"),
  118. // GPU: prompt("choose graphics: built-in or discrete "),
  119. // GPU_memory: +prompt(
  120. // "if you chose discrete graphics, select the amount of video memory you want "
  121. // ),
  122. // display: {
  123. // width: +prompt("enter width of resolution"),
  124. // height: +prompt("enter height of resolution"),
  125. // refresh_rate: prompt("What level of screen refresh is right for you?"),
  126. // },
  127. // storage: {
  128. // type: prompt("SSD or HDD"),
  129. // volume: +prompt("How many Gb you need?"),
  130. // },
  131. // };
  132. // imperative array fill 3----------------------------------------------------------------------------------;
  133. // let foodList = [
  134. // prompt("Enter 1 product in list"),
  135. // prompt("Enter 1 product in list"),
  136. // prompt("Enter 1 product in list"),
  137. // ];
  138. // while confirm--------------------------------------------------------------------------------------------;
  139. // let userConfirm;
  140. // do {
  141. // userConfirm = confirm("Do you want buy anything?");
  142. // console.log(userConfirm);
  143. // } while (userConfirm == false);
  144. // array fill-----------------------------------------------------------------------------------------------;
  145. // let productsList = [];
  146. // do {
  147. // userChoice = prompt("What you must buy in shop?");
  148. // productsList.push(userChoice);
  149. // console.log(productsList);
  150. // } while (userChoice !== null);
  151. // array fill nopush----------------------------------------------------------------------------------------;
  152. // let productsList = [];
  153. // let userChoice;
  154. // for (i = 0; userChoice !== null; i++) {
  155. // userChoice = prompt("What you must buy in shop?");
  156. // productsList[i] = userChoice;
  157. // console.log(productsList);
  158. // }
  159. // infinite probability-------------------------------------------------------------------------------------;
  160. // for (let i = 0; true; i++)
  161. // if (Math.random() > 0.9) {
  162. // alert(++i);
  163. // break;
  164. // }
  165. // empty loop-----------------------------------------------------------------------------------------------;
  166. // for (; userSays !== null; ) {
  167. // userSays = prompt("Type anything");
  168. // }
  169. // console.log(userSays);
  170. // progression sum------------------------------------------------------------------------------------------;
  171. // function fn(n) {
  172. // for (let s = (i = 1); i < n; s += i += 3) {}
  173. // return s;
  174. // }
  175. // alert(fn(7));
  176. // chess one line-------------------------------------------------------------------------------------------;
  177. // let str = "";
  178. // for (i = 0; i <= 10; i++) {
  179. // str += "" + "#";
  180. // }
  181. // console.log(str);
  182. // numbers--------------------------------------------------------------------------------------------------;
  183. // let numbers = "";
  184. // for (j = 0; j <= 9; j++) {
  185. // numbers += "\n";
  186. // for (i = 0; i <= 9; i++) {
  187. // numbers += "" + i;
  188. // }
  189. // }
  190. // console.log(numbers);
  191. // chess----------------------------------------------------------------------------------------------------;
  192. // const dot = ".";
  193. // const tag = "#";
  194. // let res = "";
  195. // for (let i = 0; i < 10; i++) {
  196. // let str = "";
  197. // for (let j = 0; j < 12; j++) {
  198. // str += (i + j) & 1 ? tag : dot;
  199. // }
  200. // res += str + "\n";
  201. // }
  202. // console.log(res);
  203. // cubes----------------------------------------------------------------------------------------------------;
  204. let cubes = [];
  205. let n = 100;
  206. for (i = 0; i < n; i++) {
  207. cubes.push(i ** 3);
  208. }
  209. console.log(cubes);
  210. // multiply table-------------------------------------------------------------------------------------------;
  211. let multiplication = Array(11);
  212. for (let i = 1; i < 11; i++) {
  213. multiplication[i] = [...Array(11)].map((_, j) => i * j);
  214. }
  215. console.log(multiplication);
  216. // matrix to html table-------------------------------------------------------------------------------------;
  217. document.write("<style>td, caption {font-family: arial}</style>");
  218. document.write('<table align="center" bgcolor="7ffa92" ');
  219. document.write('cellspacing="0" cellpadding="4" ');
  220. document.write('border="2" style="border-collapse: collapse">');
  221. document.write(
  222. "<caption><p><b>Multiplication table in decimal system</caption></b>"
  223. );
  224. for (let row = 0; row <= 10; row++) {
  225. document.write("<tr>");
  226. for (let col = 0; col <= 10; col++) {
  227. if (row == 0 || col == 0) {
  228. codeTD = '<td align="center" width="4%" bgcolor="b1c4b4">';
  229. if (row == col) {
  230. codeContent = "<b>&#" + "215;</b>";
  231. } else if (row == 0) {
  232. codeContent = "<b>" + col + "</b>";
  233. } else if (col == 0) {
  234. codeContent = "<b>" + row + "</b>";
  235. }
  236. } else {
  237. codeTD = '<td align="center">';
  238. if (row == col) {
  239. codeContent = "<b>" + row * col + "</b>";
  240. } else {
  241. codeContent = row * col;
  242. }
  243. }
  244. document.write(codeTD + codeContent + "</td>");
  245. }
  246. document.write("</tr>");
  247. }
  248. document.write("<table>");
  249. // Задание на синий пояс: Треугольник-----------------------------------------------------------------------;
  250. let lines = (line = 6),
  251. a = ".",
  252. b = "#";
  253. for (; line-- > 0; )
  254. console.log(
  255. Array(line + 1).join(a) +
  256. Array(2 * (lines - line)).join(b) +
  257. Array(line + 1).join(a)
  258. );
  259. // Задание на черный пояс: Электронная гадалка--------------------------------------------------------------;