myjs.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /* html tree */
  2. let body = {
  3. tagName: 'body',
  4. subTags: [
  5. {
  6. tagName: 'div',
  7. subTags: [
  8. {
  9. tagName: 'span',
  10. text: 'Enter a data please',
  11. },
  12. {
  13. tagName: 'br',
  14. },
  15. {
  16. tagName: 'input',
  17. attrs: {
  18. type: 'text',
  19. id: 'name'
  20. },
  21. },
  22. {
  23. tagName: 'input',
  24. attrs: {
  25. type: 'text',
  26. id: 'surname'
  27. }
  28. }
  29. ]
  30. },
  31. {
  32. tagName: 'div',
  33. subTags: [
  34. {
  35. tagName: 'button',
  36. attrs: {
  37. id: 'ok'
  38. },
  39. text: 'OK'
  40. },
  41. {
  42. tagName: 'button',
  43. attrs: {
  44. id: 'cancel'
  45. },
  46. text: 'Cancel'
  47. },
  48. ]
  49. }
  50. ]
  51. }
  52. body.subTags[1].subTags[1].text
  53. body.subTags[0].subTags[1].attrs.id
  54. /* declarative fields */
  55. var notebook = {
  56. brand: prompt("Enter a brand"),
  57. type: prompt("Enter a type"),
  58. model: prompt("Enter a model"),
  59. ram: +prompt("Enter a ram"),
  60. size: prompt("Enter a size"),
  61. weight: +prompt("Enter a weight"),
  62. resolution: {
  63. width: +prompt("Enter a width"),
  64. height: +prompt("Enter a height"),
  65. },
  66. owner: 'Anton'
  67. };
  68. var phone = {
  69. brand: prompt("Enter a brand"),
  70. model: prompt("Enter a model"),
  71. ram: +prompt("Enter a ram"),
  72. color: prompt("Enter a color"),
  73. owner: 'Anton'
  74. };
  75. var person = {
  76. name: prompt("Enter a name"),
  77. surname: prompt("Enter a surname"),
  78. married: confirm("Are you a married?"),
  79. smartphone: 'iPhone',
  80. laptop: 'Lenovo'
  81. }
  82. /* object links */
  83. person.smartphone = phone
  84. person.laptop = notebook
  85. notebook.owner = person
  86. phone.owner = person
  87. /* imperative array fill 3 */
  88. let arr = []
  89. arr[0] = prompt('Напишите слово')
  90. arr[1] = prompt('Напишите слово')
  91. arr[2] = prompt('Напишите слово')
  92. alert(arr)
  93. /* while confirm */
  94. let round;
  95. while (round != true) {
  96. round = confirm('Вы человек?');
  97. if (round) {
  98. break;
  99. }
  100. }
  101. /* array fill */
  102. let arr1 = [];
  103. let value;
  104. do {
  105. value = prompt("Введите что-то")
  106. if (value) {
  107. arr1.push(value);
  108. } else {
  109. break;
  110. }
  111. } while (value)
  112. /* array fill nopush */
  113. let arr4 = [];
  114. let value1;
  115. for (let i = 0; i != null; i++) {
  116. value1 = prompt('Напишите слово')
  117. if (value1) {
  118. arr4[i] = value1
  119. }
  120. else {
  121. break
  122. }
  123. }
  124. /* infinite probability */
  125. let random = Math.random();
  126. let result = 0;
  127. while (random) {
  128. random = Math.random();
  129. result += 1;
  130. if (random > 0.9) {
  131. alert("Компьютер выполнил " + result + " циклов.");
  132. break
  133. }
  134. }
  135. /* empty loop */
  136. do {
  137. } while (prompt('Напишите слово') == null || false)
  138. /* progression sum */
  139. var sum = 0;
  140. for (var i = 1; i <= 27; i = i + 3) {
  141. console.log(i);
  142. sum = sum + i;
  143. }
  144. console.log(sum)
  145. /* chess one line */
  146. let chessStr = ' ';
  147. for (let i = 0; i < 10; i++) {
  148. if (i % 2 === 0) {
  149. chessStr += " ";
  150. } else {
  151. chessStr += "#";
  152. }
  153. }
  154. console.log(chessStr)
  155. /* numbers */
  156. let numbers;
  157. for (let i = 0; i <= 10; i++) {
  158. for (let a = 0; a < 10; a++) {
  159. numbers = numbers + a;
  160. if (a == 9) {
  161. numbers = numbers + '\n'
  162. }
  163. }
  164. if (i == 10) {
  165. console.log(numbers);
  166. break;
  167. }
  168. }
  169. /* chess */
  170. let chess;
  171. for (let i = 0; i < 10; i++) {
  172. if (i > 0) chess += "\n";
  173. for (let j = 0; j < 12; j++) {
  174. if ((j + i) % 2 === 0) {
  175. chess += ".";
  176. } else {
  177. chess += "#";
  178. }
  179. }
  180. }
  181. console.log(chess)
  182. /* cubes */
  183. let index = [];
  184. for (let i = 0; i <= 10; i++) {
  185. index.push(i * i * i);
  186. }
  187. console.log(index)
  188. /* multiply table */
  189. let arr3 = []
  190. for (let i = 0; i <= 10; i++) {
  191. let arr4 = []
  192. arr3.push(arr4)
  193. for (let a = 0; a <= 10; a++) {
  194. arr4.push(i * a)
  195. }
  196. }
  197. console.log(arr3)
  198. /* Задание на синий пояс: треугольник */
  199. let delta = '';
  200. for (let i = 0; i < 1; i++) {
  201. for (let j = 0; j <= 11; j++) {
  202. if (j == 11) {
  203. delta = delta + '\n'
  204. }
  205. else if (j === 5) {
  206. delta = delta + '#'
  207. }
  208. else {
  209. delta = delta + '.'
  210. }
  211. }
  212. for (let j = 0; j <= 11; j++) {
  213. if (j == 11) {
  214. delta = delta + '\n'
  215. }
  216. else if (j === 4 || j === 5 || j === 6) {
  217. delta = delta + '#'
  218. }
  219. else {
  220. delta = delta + '.'
  221. }
  222. }
  223. for (let j = 0; j <= 11; j++) {
  224. if (j == 11) {
  225. delta = delta + '\n'
  226. }
  227. else if (j === 3 || j === 4 || j === 5 || j === 6 || j === 7) {
  228. delta = delta + '#'
  229. }
  230. else {
  231. delta = delta + '.'
  232. }
  233. }
  234. for (let j = 0; j <= 11; j++) {
  235. if (j == 11) {
  236. delta = delta + '\n'
  237. }
  238. else if (j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8) {
  239. delta = delta + '#'
  240. }
  241. else {
  242. delta = delta + '.'
  243. }
  244. }
  245. for (let j = 0; j <= 11; j++) {
  246. if (j == 11) {
  247. delta = delta + '\n'
  248. }
  249. else if (j === 1 || j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8 || j === 9) {
  250. delta = delta + '#'
  251. }
  252. else {
  253. delta = delta + '.'
  254. }
  255. }
  256. for (let j = 0; j <= 11; j++) {
  257. if (j == 11) {
  258. delta = delta + '\n'
  259. }
  260. else if (j === 0 || j === 1 || j === 2 || j === 3 || j === 4 || j === 5 || j === 6 || j === 7 || j === 8 || j === 9 || j === 10) {
  261. delta = delta + '#'
  262. }
  263. else {
  264. delta = delta + '.'
  265. }
  266. }
  267. }
  268. console.log(delta)