index.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. //html tree
  12. let body = {
  13. tagName : 'body',
  14. subTags : [
  15. {
  16. tagName : 'div',
  17. subTags : [
  18. {
  19. tagName : 'span',
  20. text: 'Enter a data please:'
  21. },
  22. {
  23. tagName : 'input',
  24. attrs : {
  25. type : 'text',
  26. id : 'id'
  27. }
  28. },
  29. {
  30. tagName : 'input',
  31. attrs : {
  32. type : 'text',
  33. id : 'surname'
  34. }
  35. }
  36. ]
  37. },
  38. {
  39. tagName : 'div',
  40. subTags : [
  41. {
  42. tagName : 'button',
  43. text : 'OK' ,
  44. attrs : {
  45. id : 'ok'
  46. }
  47. },
  48. {
  49. tagName : 'button' ,
  50. text : 'Cancel',
  51. attrs : {
  52. id : 'cancel'
  53. }
  54. }
  55. ]
  56. }
  57. ]
  58. }
  59. body.subTags[1].subTags[1]
  60. body.subTags[0].subTags[2].attrs.id
  61. //declarative fields
  62. var notebook = {
  63. brand: prompt("Введите название бренда :"),
  64. type: prompt("Введите серию :"),
  65. model: prompt("Введите модель :"),
  66. ram: confirm("Память 4 gb ?"),
  67. size: prompt("Введите размер:"),
  68. weight: confirm("Вес 1.8 ?"),
  69. resolution: {
  70. width:confirm("Ширина экрана 1920 ?"),
  71. height: confirm("Высота 1080 ?"),
  72. },
  73. owner : {}
  74. };
  75. var phone = {
  76. brand: prompt("Введите название бренда:"),
  77. model: prompt("Введите модель:"),
  78. ram: confirm("Память 2 gb ?"),
  79. color: prompt("Введите цвет :"),
  80. owner : {}
  81. };
  82. var person = {
  83. name: prompt("Введите ваше имя:"),
  84. surname: prompt("Введите вашу фамилию:"),
  85. married: confirm("Вы женаты/замужем ? "),
  86. smartphone: {},
  87. laptop:{}
  88. }
  89. //object links
  90. person.smartphone = phone
  91. person.laptop = notebook
  92. notebook.owner = person
  93. phone.owner = person
  94. // person.smartphone.owner.laptop.owner.smartphone == person.smartphone
  95. // imperative array fill 3
  96. let imperatArray = []
  97. for (let i = 0; i < 3; i++) {
  98. imperatArray.push(prompt('Введите числа:'))
  99. }
  100. console.log(imperatArray)
  101. // while confirm
  102. let askUser = confirm('Нажмите ОТМЕНА чтобы выйти отсюда ...')
  103. while (askUser != true) {
  104. askUser = confirm('Нажмите ОТМЕНА чтобы выйти отсюда ...')
  105. }
  106. //array fill
  107. let elements = []
  108. while (true) {
  109. let quesUser = prompt("Введите число :")
  110. elements.push(quesUser)
  111. if (!quesUser) {
  112. break;
  113. }
  114. }
  115. //array fill nopush
  116. let elementsSecond = []
  117. while (true) {
  118. var quesUserSecond = prompt(["Введите число :"])
  119. if (elementsSecond[quesUserSecond]){
  120. elementsSecond[quesUserSecond]++;
  121. }else {
  122. elementsSecond[quesUserSecond] = 1;
  123. }
  124. if (!quesUserSecond) {
  125. break;
  126. }
  127. }
  128. //infinite probability
  129. while(true) {
  130. var infiniteProb = Math.random();
  131. alert(infiniteProb);
  132. if (infiniteProb > 0.9) {
  133. break;
  134. }
  135. }
  136. //empty loop
  137. do {
  138. } while (prompt("Нажмите отмена") == null);
  139. //progression sum
  140. let d = 3;
  141. let n = 150;
  142. for (let a1 = 1; 1 + d < n ; a1++) {
  143. let an = a1 + d * (n-1)
  144. let sn = ((a1 + an) * n)/2
  145. console.log("Последний член an : " + an)
  146. console.log("Сумма арифметической прогрессии Sn : " + sn)
  147. break;
  148. }
  149. // chess one line
  150. let grid = "#";
  151. for (let i = 0; i < 9 ;i++) {
  152. if (i % 2) {
  153. grid = grid + "#";
  154. }else {
  155. grid = grid + " ";
  156. }
  157. } console.log (grid);
  158. //numbers
  159. let str = '';
  160. for ( let j = 0; j <= 9 ; j++){
  161. for (let i = 0; i <= 9; i++) {
  162. str = str + i;
  163. if (i == 9) {
  164. str = str + '\n'
  165. }
  166. }
  167. if (j == 9) {
  168. console.log(str)
  169. break;
  170. }
  171. }
  172. //chess
  173. let chess = "";
  174. for (let i = 0;i <= 10; i++){
  175. chess += '\n'
  176. for (let j = 0; j <= 6; j++){
  177. if (i % 2 === 0 && j === 0) {
  178. chess += "#"
  179. }else chess += ".#"
  180. }
  181. }
  182. console.log(chess)
  183. //cubes
  184. for (let cub = [];;) {
  185. let index = cub.length
  186. for (let i = 0; i < 1;i++) {
  187. let result = index ** 3
  188. cub.push(result)
  189. }
  190. if (cub.length == 10){
  191. console.log(cub)
  192. break;
  193. }
  194. }
  195. //multiply table
  196. let arr = [];
  197. for(let i = 0; i <= 10; i++) {
  198. let table = []
  199. arr.push(table)
  200. for(let j = 0; j <= 10; j++) {
  201. table.push(j * i)
  202. }
  203. }
  204. // matrix to html table
  205. let str = '<table border = "1">';
  206. for(let i = 0; i <= 0; i++) {
  207. str += '<tr> <td> FIRST </td>'
  208. for(let j = 0; j <= 0; j++) {
  209. str += '<td> SECOND </td> </tr>'
  210. }
  211. }
  212. str += "</table>"
  213. document.write(str)
  214. //Задание на синий пояс: Треугольник
  215. let triangle = "";
  216. for (let i = 0; i <= 10 ; i++){
  217. triangle += '\n'
  218. for (let j = 0; j <= 11; j++) {
  219. triangle += '.' + '#'
  220. }
  221. }
  222. </script>
  223. </body>
  224. </html>