main.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // html tree
  2. {
  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. console.log(body.subTags[1].subTags[1].text);
  54. console.log(body.subTags[0].subTags[3].attrs.id);
  55. // declarative fields and object links
  56. {
  57. var notebook = {
  58. brand: prompt("Введите марку ноутбука"),
  59. type: prompt("Введите тип"),
  60. model: prompt("Введите модель ноутбука"),
  61. ram: +prompt("Введите количесство оперативки"),
  62. size: +prompt("Введите диагональ экрана"),
  63. weight: +prompt("Вес ноутбука"),
  64. resolution: {
  65. width: +prompt("Ширина экрана ноутбука"),
  66. height: +prompt("Высота экрана ноутбука"),
  67. },
  68. owner: person,
  69. };
  70. var phone = {
  71. brand: prompt("Введите марку телефона"),
  72. model: prompt("Введите модель телефона"),
  73. ram: +prompt("Введите количество оперативки"),
  74. color: prompt("Введите цвет телефона"),
  75. owner: person,
  76. };
  77. var person = {
  78. name: prompt("Введите имя"),
  79. surname: prompt("Введите фамилию"),
  80. married: confirm("женат"),
  81. smartphone: phone,
  82. laptop: notebook,
  83. }
  84. }
  85. // imperative array fill 3
  86. {
  87. let arr = [];
  88. arr[0] = prompt('Введите первый элемент массива'),
  89. arr[1] = prompt('Введите второй элемент массива'),
  90. arr[2] = prompt('Введите третий элемент массива');
  91. }
  92. // while confirm
  93. let cycle = confirm();
  94. while (cycle == false) {
  95. cycle = confirm();
  96. if (cycle) {
  97. break;
  98. }
  99. }
  100. // array fill
  101. {
  102. let arr = [];
  103. let arrPush = []
  104. while (arr) {
  105. arrPush.push(arr = prompt())
  106. if (arr === null) {
  107. break;
  108. }
  109. }
  110. }
  111. // array fill nopush
  112. {
  113. let arrNoPush = []
  114. for (let i = 0; i != null; i++) {
  115. arrNoPush[i] = prompt("Введите для примера что-то!");
  116. if (arrNoPush[i] === null)
  117. break;
  118. }
  119. }
  120. // infinite probability
  121. {
  122. let number = 0;
  123. while (true) {
  124. let randomNumber = Math.random();
  125. number++;
  126. if (randomNumber > 0.9) {
  127. alert("количество итераций " + number);
  128. alert("Случайное число " + randomNumber);
  129. break;
  130. }
  131. }
  132. }
  133. // empty loop
  134. // progression sum
  135. for (let i = 0; i < 10000; i++) {
  136. console.log(i);
  137. }
  138. // chess one line
  139. {
  140. let i = '#';
  141. let str = " ";
  142. for (j = 0; j < 5; j++) {
  143. str += i + " ";
  144. }
  145. console.log(str);
  146. }
  147. // numbers
  148. {
  149. let numbers = "";
  150. for (let i = 0; i <= 9; i++) {
  151. for (let a = 0; a <= 9; a++) {
  152. numbers += a;
  153. }
  154. numbers += "\n";
  155. }
  156. console.log(numbers);
  157. }
  158. // chess
  159. {
  160. let boardChess = "";
  161. for (let i = 0; i < 10; i++) {
  162. for (let a = 0; a < 12; a++) {
  163. boardChess += (a % 2) == (i % 2) ? "." : "#";
  164. }
  165. boardChess += "\n";
  166. }
  167. console.log(boardChess);
  168. }
  169. // cubes
  170. for (let indexСubes = []; ;) {
  171. let index = indexСubes.length;
  172. let expon = index ** 3;
  173. indexСubes.push(expon);
  174. if (indexСubes.length == 20) {
  175. console.log(indexСubes);
  176. break;
  177. }
  178. }
  179. // multiply table
  180. let arr = Array(10);
  181. for (let i = 1; i < 10; i++) {
  182. arr[i] = [...Array(10)].map((_, j) => i * j);
  183. }
  184. console.log(arr[5][6]);
  185. console.log(arr[7][2]);
  186. // Задание на синий пояс: Треугольник,нужно еще пофиксить
  187. // let i = 0,
  188. // j = 0;
  189. // let point = "",
  190. // lattice = "";
  191. // while (i < 5) {
  192. // point = "";
  193. // lattice = "";
  194. // for (j = 0; j < 5 - i; j++) point += ".";
  195. // for (j = 0; j < 2 * i + 1; j++) lattice += "#";
  196. // console.log(point + lattice + point);
  197. // i++;
  198. // }
  199. }