main.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. }
  97. // array fill
  98. {
  99. let arr = [];
  100. let arrPush = []
  101. while (arr) {
  102. arrPush.push(arr = prompt())
  103. if (arr === null) {
  104. break;
  105. }
  106. }
  107. }
  108. // array fill nopush
  109. {
  110. let arrNoPush = []
  111. for (let i = 0; i != null; i++) {
  112. arrNoPush[i] = prompt("Введите для примера что-то!");
  113. if (arrNoPush[i] === null)
  114. break;
  115. }
  116. }
  117. // infinite probability
  118. {
  119. let number = 0;
  120. while (true) {
  121. let randomNumber = Math.random();
  122. number++;
  123. if (randomNumber > 0.9) {
  124. alert("количество итераций " + number);
  125. alert("Случайное число " + randomNumber);
  126. break;
  127. }
  128. }
  129. }
  130. // empty loop
  131. // progression sum
  132. for (let i = 0; i < 10000; i++) {
  133. console.log(i);
  134. }
  135. // chess one line
  136. {
  137. let i = '#';
  138. let str = " ";
  139. for (j = 0; j < 5; j++) {
  140. str += i + " ";
  141. }
  142. console.log(str);
  143. }
  144. // numbers
  145. {
  146. let numbers = "";
  147. for (let i = 0; i <= 9; i++) {
  148. for (let a = 0; a <= 9; a++) {
  149. numbers += a;
  150. }
  151. numbers += "\n";
  152. }
  153. console.log(numbers);
  154. }
  155. // chess
  156. {
  157. let boardChess = "";
  158. for (let i = 0; i < 10; i++) {
  159. for (let a = 0; a < 12; a++) {
  160. boardChess += (a % 2) == (i % 2) ? "." : "#";
  161. }
  162. boardChess += "\n";
  163. }
  164. console.log(boardChess);
  165. }
  166. // cubes
  167. for (let indexСubes = []; ;) {
  168. let index = indexСubes.length;
  169. let expon = index ** 3;
  170. indexСubes.push(expon);
  171. if (indexСubes.length == 20) {
  172. console.log(indexСubes);
  173. break;
  174. }
  175. }
  176. // multiply table
  177. let arr = Array(10);
  178. for (let i = 1; i < 10; i++) {
  179. arr[i] = [...Array(10)].map((_, j) => i * j);
  180. }
  181. console.log(arr[5][6]);
  182. console.log(arr[7][2]);
  183. // Задание на синий пояс: Треугольник,нужно еще пофиксить
  184. let i = 0,
  185. j = 0;
  186. let point = "",
  187. lattice = "";
  188. while (i <= 5) {
  189. point = "";
  190. lattice = "";
  191. for (j = 0; j < 5 - i; j++) point += ".";
  192. for (j = 0; j < 2 * i + 1; j++) lattice += "#";
  193. console.log(point + lattice + point);
  194. i++;
  195. }
  196. }