tree_structure.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. };
  101. let clientCard = {
  102. name: prompt("Enter your name, please"),
  103. surname: prompt("Enter your surname, please"),
  104. age: +prompt("Enter your age, please"),
  105. education: prompt(
  106. "enter your educational level (higher education, secondary education, etc."
  107. ),
  108. gender: prompt("choose your gender: man, woman"),
  109. sallery: +prompt("what is your annual income?"),
  110. };
  111. let noteOfDream = {
  112. brand: prompt("what brand of laptop would you like?"),
  113. model: prompt("select laptop model "),
  114. CPU: prompt("select the CPU"),
  115. GPU: prompt("choose graphics: built-in or discrete "),
  116. GPU_memory: +prompt(
  117. "if you chose discrete graphics, select the amount of video memory you want "
  118. ),
  119. display: {
  120. width: +prompt("enter width of resolution"),
  121. height: +prompt("enter height of resolution"),
  122. refresh_rate: prompt("What level of screen refresh is right for you?"),
  123. },
  124. storage: {
  125. type: prompt("SSD or HDD"),
  126. volume: +prompt("How many Gb you need?"),
  127. },
  128. };
  129. clientsCar.owner = clientCard.name;
  130. clientCard.car = clientsCar.brand;
  131. clientCard.notebook = noteOfDream.brand;
  132. console.log(clientsCar);
  133. console.log(clientCard);
  134. console.log(noteOfDream);
  135. // imperative array fill 3----------------------------------------------------------------------------------;
  136. // let foodList = [
  137. // prompt("Enter 1 product in list"),
  138. // prompt("Enter 1 product in list"),
  139. // prompt("Enter 1 product in list"),
  140. // ];
  141. // while confirm--------------------------------------------------------------------------------------------;
  142. // let userConfirm;
  143. // do {
  144. // userConfirm = confirm("Do you want buy anything?");
  145. // console.log(userConfirm);
  146. // } while (userConfirm == false);
  147. // array fill-----------------------------------------------------------------------------------------------;
  148. // let productsList = [];
  149. // do {
  150. // userChoice = prompt("What you must buy in shop?");
  151. // productsList.push(userChoice);
  152. // console.log(productsList);
  153. // } while (userChoice !== null);
  154. // array fill nopush----------------------------------------------------------------------------------------;
  155. // let productsList = [];
  156. // let userChoice;
  157. // for (i = 0; userChoice !== null; i++) {
  158. // userChoice = prompt("What you must buy in shop?");
  159. // productsList[i] = userChoice;
  160. // console.log(productsList);
  161. // }
  162. // infinite probability-------------------------------------------------------------------------------------;
  163. // for (let i = 0; true; i++)
  164. // if (Math.random() > 0.9) {
  165. // alert(++i);
  166. // break;
  167. // }
  168. // empty loop-----------------------------------------------------------------------------------------------;
  169. while (prompt() === null);
  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 online-------------------------------------------------------------------------------------------;
  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 = 0; 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. }