Js-HW4.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. let body = {
  2. tagName: 'body',
  3. children: [
  4. {
  5. tagName: 'div',
  6. children: [
  7. {
  8. tagName: 'span',
  9. innerText: 'Enter a data please:'
  10. },
  11. {
  12. tagName: 'br'
  13. },
  14. {
  15. tagName: 'input',
  16. type: 'text',
  17. id: 'name'
  18. },
  19. {
  20. tagName: 'input',
  21. type: 'text',
  22. id: 'surname'
  23. }
  24. ]
  25. },
  26. {
  27. tagName: 'div',
  28. children: [
  29. {
  30. tagName: 'button',
  31. innerText: 'OK',
  32. id: 'ok'
  33. },
  34. {
  35. tagName: 'button',
  36. innerText: 'Cancel',
  37. id: 'cancel'
  38. }
  39. ]
  40. }
  41. ]
  42. };
  43. console.log(body.children[1].children[1].innerText)
  44. console.log(body.children[0].children[3].id)
  45. var person;
  46. var notebook = {
  47. brand: prompt('Brand:'),
  48. type: prompt('Type:'),
  49. model: prompt('Model:'),
  50. ram: +prompt('Ram:'),
  51. size: +prompt('Size:'),
  52. weight: +prompt('Weight:'),
  53. resolution: {
  54. width: +prompt('Resolution width:'),
  55. height: +prompt('Resolution height:'),
  56. },
  57. owner: person
  58. };
  59. var phone = {
  60. brand: prompt('Brand:'),
  61. model: prompt('Model:'),
  62. ram: +prompt('Ram:'),
  63. color: prompt('Color:'),
  64. owner: person
  65. };
  66. person = {
  67. name: prompt('Name:'),
  68. surname: prompt('Surname:'),
  69. married: confirm('Married?'),
  70. smartphone: phone,
  71. laptop: notebook
  72. };
  73. let array1 = []
  74. array1[0] = prompt('string 1');
  75. array1[1] = prompt('string 2');
  76. array1[2] = prompt('string 3');
  77. let confirm1;
  78. while(!confirm1) {
  79. confirm1 = confirm('Are you hungry?');
  80. if(confirm1) {
  81. break;
  82. }
  83. }
  84. let prompt1;
  85. let array2 = []
  86. while(prompt1 !== null) {
  87. prompt1 = prompt('Enter something');
  88. array2.push(prompt1)
  89. if(!prompt1) {
  90. break
  91. }
  92. console.log(array2)
  93. }
  94. let prompt2 = prompt('Enter something');
  95. let array3 = []
  96. do {
  97. let i = 0;
  98. prompt2 ? array3[i++] = prompt2 : null
  99. console.log(array3)
  100. } while(prompt2 !== null)
  101. let i = 0;
  102. let n;
  103. while(n !== 5) {
  104. i++
  105. let n = Math.random() * 5;
  106. console.log(n)
  107. console.log(i)
  108. if(n === 5) {
  109. break
  110. }
  111. }
  112. let end = +prompt('Введите крайнее число прогрессии')
  113. let sum = 0;
  114. for(let i = 1; i < 30; i+=3){
  115. console.log(i)
  116. sum += i
  117. }
  118. alert(`Сумма чисел в прогрессии - ${sum}`);
  119. let chessString = '';
  120. for(let i = 0; i < 10; i++) {
  121. i % 2 === 0 ? chessString += ' ' : chessString += '#'
  122. }
  123. console.log(chessString);
  124. let numbers2 = '';
  125. for(let i = 0; i < 10; i++) {
  126. numbers2 += '\n'
  127. for(let j = 0; j < 10; j++) {
  128. numbers2 += j
  129. }
  130. }
  131. console.log(numbers2)
  132. let height = 8;
  133. let width = 10;
  134. let board = "";
  135. for (let i = 0; i < height; i++) {
  136. if(i > 0) board += "\n";
  137. for (let j = 0; j < width; j++) {
  138. if ((j + i) % 2 === 0){
  139. board += ".";
  140. } else {
  141. board += "#";
  142. }
  143. }
  144. }
  145. console.log(board);
  146. let numbers = [];
  147. for(let i = 0; i < 15; i++) {
  148. numbers.push(Math.pow(i, 3));
  149. }
  150. console.log(numbers)
  151. let multiplyTable = [];
  152. for(let i = 0; i <= 9; i++) {
  153. let nestedArr = []
  154. multiplyTable.push(nestedArr)
  155. for(let j = 0; j <= 9; j++) {
  156. nestedArr.push([j * i])
  157. }
  158. }
  159. console.log(multiplyTable[5][6])
  160. let table = document.createElement('table')
  161. for(let i = 1; i <= 9; i++) {
  162. let tr = document.createElement('tr');
  163. for(let j = 1; j <= 9; j++) {
  164. let td = document.createElement('td')
  165. td.innerHTML = String(j * i)
  166. tr.appendChild(td)
  167. }
  168. table.appendChild(tr)
  169. }
  170. document.body.appendChild(table)