script.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. "use strict";
  2. function htmlTree() {
  3. let body = {
  4. tagName: 'body',
  5. subTags: [{
  6. tagName: 'div',
  7. subTags: [{
  8. tagName: "span",
  9. text: "Enter a data please:",
  10. },
  11. {
  12. tagName: "input",
  13. attrs: {
  14. type: "text",
  15. id: "name",
  16. },
  17. },
  18. {
  19. tagName: "input",
  20. attrs: {
  21. type: "text",
  22. id: "surname",
  23. },
  24. },
  25. ]
  26. },
  27. {
  28. tagName: 'div',
  29. subTags: [{
  30. tagName: "button",
  31. text: "OK",
  32. attrs: {
  33. id: "ok",
  34. },
  35. },
  36. {
  37. tagName: "button",
  38. text: "Cancel",
  39. attrs: {
  40. id: "cancel",
  41. },
  42. },
  43. ]
  44. }
  45. ]
  46. }
  47. console.log(body.subTags[1].subTags[1].text);
  48. console.log(body.subTags[0].subTags[2].attrs.id);
  49. }
  50. // htmlTree()
  51. function declarativeFields() {
  52. let notebook = {
  53. brand: prompt("Enter a brand your notebook", "HP"),
  54. type: prompt("Enter a type your notebook", "440 G4"),
  55. model: prompt("Enter a model your notebook", "Y7Z75EA"),
  56. ram: +prompt("Enter a ram your notebook", "4"),
  57. size: prompt("Enter a size your notebook", "14"),
  58. weight: +prompt("Enter a weight your notebook", "1.8,"),
  59. resolution: {
  60. width: +prompt("Enter a screen width in px", "1920"),
  61. height: +prompt("Enter a screen height in px", "1080"),
  62. },
  63. owner: prompt("Enter the owner of the notebook", "Alex"),
  64. };
  65. let phone = {
  66. brand: prompt("Enter a brand your phone", "meizu"),
  67. model: prompt("Enter a model your phone", "m2"),
  68. ram: +prompt("Enter a ram your phone", "2"),
  69. color: prompt("Enter a color your phone", "black"),
  70. owner: prompt("Enter the owner of the phone", "Kate"),
  71. };
  72. let person = {
  73. name: prompt("Enter a your name", "Donald"),
  74. surname: prompt("Enter a your surname", "Trump"),
  75. married: confirm("Are you married?"),
  76. smartphone: confirm("Do you have a smartphone?"),
  77. laptop: confirm("Do you have a laptop?"),
  78. }
  79. person.smartphone = notebook;
  80. notebook.owner = person;
  81. person.laptop = phone;
  82. phone.owner = person;
  83. console.log(person.smartphone.owner.laptop.owner.smartphone == person.smartphone)
  84. }
  85. // declarativeFields()
  86. function imperativeArray() {
  87. let arr = [];
  88. for (let i = 0; i < 3; i++) {
  89. let userAnswer = prompt("Напиши 3 своих любимых сериала", "");
  90. arr.push(userAnswer);
  91. }
  92. console.log(arr);
  93. }
  94. // imperativeArray()
  95. function whileConfirm() {
  96. while (confirm("Hi") == false) {
  97. if (confirm("Hi") !== false) {
  98. break;
  99. }
  100. }
  101. }
  102. // whileConfirm()
  103. function arrayFill() {
  104. let arr = [];
  105. while (true) {
  106. let userAnswer = prompt("Перечисли свои любимые фильмы", "");
  107. if (isNaN(userAnswer)) {
  108. arr.push(userAnswer);
  109. };
  110. if (userAnswer == null) {
  111. break;
  112. }
  113. }
  114. console.log(arr);
  115. }
  116. // arrayFill()
  117. function arrayFillNopush() {
  118. let arr = [];
  119. let i = 0;
  120. while (true) {
  121. let userAnswer = prompt("Перечисли свои любимые фильмы", "");
  122. if (isNaN(userAnswer)) {
  123. arr[i] = userAnswer;
  124. }
  125. if (userAnswer == null) {
  126. break;
  127. }
  128. i++;
  129. }
  130. console.log(arr);
  131. }
  132. // arrayFillNopush()
  133. function infiniteProbability() {
  134. let i = 0;
  135. let randomNumber = 0;
  136. while (true) {
  137. randomNumber = Math.random(i);
  138. if (randomNumber > 0.9) {
  139. break;
  140. }
  141. i++;
  142. console.log(randomNumber);
  143. }
  144. alert(i);
  145. }
  146. // infiniteProbability()
  147. function emptyLoop() {
  148. while (prompt() === null) {}
  149. }
  150. // emptyLoop()
  151. function progressionSum() {
  152. let userNumber = prompt("Введите число", "");
  153. let progressionSum = 0;
  154. for (let i = 0; i < userNumber; i++) {
  155. progressionSum = progressionSum + (1 + (i * 3));
  156. }
  157. console.log(progressionSum);
  158. }
  159. // progressionSum()
  160. function chessOneLine() {
  161. let str = "";
  162. for (let i = 0; i < 5; i++) {
  163. str += "# ";
  164. }
  165. console.log(str);
  166. }
  167. // chessOneLine()
  168. function numbers() {
  169. let str = "";
  170. for (let a = 0; a < 10; a++) {
  171. for (let i = 0; i < 10; i++) {
  172. str += i;
  173. }
  174. str += "\n";
  175. }
  176. console.log(str);
  177. }
  178. // numbers()
  179. function chess() {
  180. let str = "";
  181. for (let i = 0; i < 10; i++) {
  182. for (let x = 0; x < 10; x++) {
  183. if ((x + i) % 2 == 0)
  184. str += ". ";
  185. else
  186. str += "# ";
  187. }
  188. str += "\n";
  189. }
  190. console.log(str);
  191. }
  192. // chess()
  193. function cubes() {
  194. let arr = [0, 1, 2, 5, 10];
  195. let num = 0;
  196. let arrMode = [];
  197. for (let key of arr) {
  198. let cube = num * num * num;
  199. arrMode.push(cube);
  200. num++;
  201. }
  202. console.log(arrMode)
  203. }
  204. // cubes()
  205. function multiplyTable() {
  206. let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  207. let arrMode = [];
  208. for (let keyN of arr) {
  209. arrMode[keyN] = [];
  210. for (let keyM of arr) {
  211. arrMode[keyN][keyM] = (keyN * keyM);
  212. }
  213. }
  214. console.log(arrMode[7][2])
  215. }
  216. // multiplyTable()
  217. function matrix() {
  218. let tab = document.getElementById("table");
  219. let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  220. let arrMode = [];
  221. let html = "<table>";
  222. for (let keyN of arr) {
  223. arrMode[keyN] = [];
  224. for (let keyM of arr) {
  225. arrMode[keyN][keyM] = (keyN * keyM);
  226. html +=
  227. `<tr>
  228. <td>${keyN}</td>
  229. <td>${keyM}</td>
  230. <td>${keyN * keyM}</td>
  231. </tr>`
  232. }
  233. }
  234. html += "</table>";
  235. tab.innerHTML = html;
  236. }
  237. // matrix()
  238. function triangle() {
  239. let i = 0,
  240. j = 0;
  241. let dot = "",
  242. grid = "";
  243. while (i < 5) {
  244. dot = "";
  245. grid = "";
  246. for (j = 1; j < 5 - i; j++) {
  247. dot += ". ";
  248. }
  249. for (j = 0; j < 2 * i + 1; j++) {
  250. grid += "# ";
  251. }
  252. console.log(dot + grid + dot);
  253. i++;
  254. }
  255. }
  256. // triangle()
  257. function electronicFortuneTeller() {
  258. let userNumber;
  259. let prediction = [];
  260. let historySize = 4;
  261. for (let i = 1; i <= 5; i++) {
  262. if (prediction.length < historySize) {
  263. console.log("prediction = RANDOM " + Math.round(Math.random()));
  264. userNumber = +prompt("Введите число", "");
  265. prediction.push(userNumber);
  266. } else {
  267. console.log("prediction = HISTORY " + prediction[0]);
  268. userNumber = +prompt("Введите число", "");
  269. prediction.push(userNumber);
  270. prediction.shift();
  271. }
  272. }
  273. }
  274. // electronicFortuneTeller()