index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //html tree
  2. let body = {
  3. tagName: "body",
  4. subTags: [
  5. {
  6. tagName: "div",
  7. subTags: [
  8. { tagName: 'span', text: 'Enter a data please:' },
  9. { tagName: 'br' },
  10. { tagName: 'input', attr: { type: 'text', id: 'name' } },
  11. { tagName: 'input', attr: { type: 'text', id: 'surname' } },
  12. ]
  13. },
  14. {
  15. tagName: 'div',
  16. subTags: [
  17. { tagName: 'button', text: 'ok', attr: { id:'ok' } },
  18. { tagName: 'button', text: 'Cancel', attr: { id: 'cancel' } }
  19. ]
  20. }
  21. ]
  22. }
  23. body.subTags[1].subTags[1].text
  24. body.subTags[0].subTags[3].attr.id
  25. //declarative fields
  26. var notebook = {
  27. brand: prompt('Enter brand'),
  28. type: prompt('Enter type'),
  29. model: prompt('Enter model'),
  30. ram: prompt('Enter ram'),
  31. size: prompt('Enter size'),
  32. weight: prompt('Enter weight'),
  33. resolution: {
  34. width: prompt('Enter width'),
  35. height: prompt('Enter height'),
  36. },
  37. };
  38. var phone = {
  39. brand: prompt('What is brand?'),
  40. model: prompt('What is model?'),
  41. ram: +prompt('Enter you ram?'),
  42. color: prompt('What is color?'),
  43. };
  44. //object links
  45. var person = {
  46. name: prompt('What is you name?'),
  47. surname: prompt("What is you surname?"),
  48. married: confirm('Are you married?'),
  49. }
  50. person.phone = phone
  51. person.notebook = notebook
  52. phone.owner = person
  53. notebook.owner = person
  54. //imperative array fill 3
  55. let th = []
  56. th[1] = prompt();
  57. th[2] = prompt();
  58. th[0] = prompt()
  59. //while confirm
  60. let qw = "";
  61. while (qw !== true) {
  62. qw = confirm('?')
  63. }
  64. //array fill
  65. let mass = [];
  66. let qu = ""
  67. while ( (qu = prompt('Чего д0бавить?')) !== null) {
  68. mass.push(qu)
  69. }
  70. //array fill nopush
  71. let mass1 = [], i=0 ;
  72. let qu1 = ""
  73. while ( (qu1 = prompt('Чего д0бавить?')) != null) {
  74. mass1[i++] = qu1
  75. }
  76. //infinite probability
  77. let numb = 0
  78. while ( Math.random() < 0.9) {
  79. numb += 1
  80. }
  81. alert(numb)
  82. //empty loop
  83. let a = ''
  84. while (a != prompt());
  85. //progression sum
  86. let aa = 0
  87. for (i = 1; i < 100; i += 3){
  88. aa = aa + i
  89. }
  90. //chess one line
  91. let q = ""
  92. for (i = 0; i < 15; i++){
  93. if (i % 2 === 1) {
  94. q = q + " "
  95. } else {
  96. q = q + "#"
  97. }
  98. }
  99. //numbers
  100. /*let w = ""
  101. for (let i = 0; i < 10; i++){
  102. w = w + "0123456789\n"
  103. }
  104. console.log(w) */
  105. str = ""
  106. for (let i = 0; i < 10; i++){
  107. str = str + '\n'
  108. for (let j = 0; j < 10; j++){
  109. str = str + j
  110. }
  111. }
  112. console.log(str)
  113. //chess
  114. let chess = ""
  115. for (let i = 0; i < 6; i++) {
  116. chess += '\n'
  117. for (let j = 0; j < 6; j++) {
  118. if (i % 2 === 1) {
  119. chess += ".#"
  120. } else {
  121. chess += "#."
  122. }
  123. }
  124. }
  125. alert(chess)
  126. // cubes
  127. let mass11 = []
  128. for (let i = 0; i < 15; i++){
  129. mass11.push(i ** 3)
  130. }
  131. console.log(mass11[i])
  132. //multiply table
  133. let mas = []
  134. for (let i = 0; i < 10; i++){
  135. mas[i] = []
  136. for (let j = 0; j < 10; j++){
  137. mas[i][j] = [j*i] ; //<============ или ============> mas[i].push(i*j)
  138. }
  139. }
  140. //matrix to html table тут страшные и непонятные вещи происходили , короче , как-то склепал
  141. document.write( "<table border='1'>")
  142. let mas = []
  143. for (let i = 1; i < 10; i++){
  144. mas[i] = []
  145. document.write("<tr>")
  146. for (let j = 1; j < 10; j++){
  147. document.write( `<td>${mas[i][j] = [j * i]}</td> `)
  148. }
  149. document.write("</tr>")
  150. }
  151. document.write("</table>")
  152. //Задание на синий пояс: Треугольник
  153. let n = 6;
  154. for (let i = 1; i <= n; i++) {
  155. let str = '';
  156. for (j = 1; j <= 2 * n - 1; j++) {
  157. if (j >= n - (i - 1) && j <= n + (i - 1)) {
  158. str += '#';
  159. } else {
  160. str += '.';
  161. }
  162. }
  163. console.log(str);
  164. }