main.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* let body ={
  2. tagName: 'body',
  3. children: [
  4. {tagName: 'div',
  5. children: [{tagName: 'span',
  6. children:["Enter a data please"]}, {tagName: 'input', attrs: {id: 'name',type:'text' }},
  7. {tagName: 'input', attrs: {id: 'surname',type:'text' }},
  8. {tagName: '/br'}
  9. ]},
  10. {tagName: 'div',
  11. children: [{tagName: 'button', attrs:{id : 'id'}},
  12. {tagName: 'button', attrs:{id: 'cancel'}}
  13. ]}
  14. ]
  15. }
  16. console.log(body.children[0].children[0].children);
  17. console.log(body.children[1].children[1].attrs.id); */
  18. /*
  19. <table border='1'>
  20. <tr>
  21. <td>
  22. 1x1
  23. </td>
  24. <td>
  25. 1x2
  26. </td>
  27. </tr>
  28. <tr>
  29. <td>
  30. 2x1
  31. </td>
  32. <td>
  33. 2x2
  34. </td>
  35. </tr>
  36. </table>
  37. */
  38. /* let table = {
  39. tagName : 'table',
  40. attrs : {
  41. border: '1'
  42. },
  43. subTags: [
  44. {
  45. tagName: 'tr',
  46. subTags: [{
  47. tagName: 'td',
  48. textInCell: '1x1'
  49. },
  50. {
  51. tagName:'td',
  52. textInCell: '1x2'
  53. }]},
  54. {
  55. tagName: 'tr',
  56. subTags: [{
  57. tagName: 'td',
  58. textInCell: '2x1'
  59. },
  60. {
  61. tagName: 'td',
  62. textInCell: '2x2'
  63. }]
  64. }
  65. ]
  66. }
  67. console.log(table.subTags[0].subTags[0].textInCell);
  68. console.log(table.subTags[1].subTags[1].textInCell); */
  69. /* let boddy = document.getElementById('body');
  70. //multiplay table
  71. let table = document.createElement('table')
  72. let tbody = document.createElement('tbody')
  73. for(let rowIndex = 1; rowIndex<10; rowIndex++){
  74. let rows = document.createElement('tr');
  75. for(let cellIndex = 1; cellIndex<10; cellIndex++){
  76. let cell = document.createElement('td');
  77. let cellText = document.createTextNode(rowIndex*cellIndex);
  78. cell.appendChild(cellText);
  79. rows.appendChild(cell);
  80. }
  81. tbody.appendChild(rows);
  82. }
  83. table.appendChild(tbody);
  84. boddy.appendChild(table);
  85. */
  86. /* let str = '<table>';
  87. for (let rowIndex = 1; rowIndex<10; rowIndex++){
  88. str+='<tr>';
  89. for(let cellIndex = 1; cellIndex<10; cellIndex++) {
  90. str+=`<td>${rowIndex*cellIndex}</td>`;
  91. }
  92. str+='</tr>'
  93. }
  94. str+='</table>';
  95. document.write(str); */
  96. /* let person = {
  97. name: prompt("Input your name", ""),
  98. surname: prompt("Input your surname", ""),
  99. married: confirm('You are married?'),
  100. }
  101. let notebook = {
  102. brand: prompt("Input brand of Notebook", ""),
  103. type: prompt("Input type of Notebook", ""),
  104. model: prompt("Input model of Notebook", ""),
  105. ram: +prompt("Input ram of Notebook", ""),
  106. size: prompt("Input size of Notebook", ""),
  107. weight: +prompt("Input weight of Notebook", ""),
  108. resolution: {
  109. width: +prompt("Input width of screen on Notebook", ""),
  110. height: +prompt("Input height of screen on Notebook", ""),
  111. },
  112. };
  113. let phone = {
  114. brand: prompt("Input brand of Phone", ""),
  115. model: prompt("Input model of Phone", ""),
  116. ram: +prompt("Input ram of Phone", ""),
  117. color: prompt("Input color of Phone", ""),
  118. };
  119. person.notebook = notebook;
  120. notebook.owner = person;
  121. person.phone = phone;
  122. phone.owner = person;
  123. console.log(person.phone.owner.notebook.owner.phone == person.phone); */
  124. /* let eternalLoop = confirm("press no pls")
  125. while(!eternalLoop){
  126. eternalLoop = confirm("press no pls");
  127. } */
  128. /* infinite probability */
  129. /* let i = 0;
  130. for(;;) {
  131. i++;
  132. if(Math.random() > 0.9){
  133. alert(`count of iterations ${i}`);
  134. break;
  135. }
  136. } */
  137. /* empty loop */
  138. /* while(null == prompt('press no to continue', "")){
  139. } */
  140. /* cubes */
  141. /*
  142. function promotionToHigherValue(arr,f) {
  143. let result = [];
  144. for(let item of arr) {
  145. result.push(f(item));
  146. }
  147. console.log(result);
  148. }
  149. promotionToHigherValue([1,2,3,4,5], x => x**3); */
  150. /* progression sum */
  151. /* let sum = 0;
  152. let lengthOfProgression = +prompt("input length of prgression", '');
  153. for (let i = 1; i<=lengthOfProgression; i+=3){
  154. sum=sum + i;
  155. }
  156. alert(sum); */
  157. /* how to write christmas tree */
  158. /*
  159. const buildTree = tier => {
  160. // more interesting solution but for me hard understand to make it by myself
  161. let s = Array(tier - 1).join(' ');
  162. for (s = s + '#' + s; tier--; console.log(s), s = s.replace(/\s(#+)\s/, '#$1#'));
  163. }
  164. buildTree(15); /* from internet solution and that so hard to understand how that magic works*/
  165. /* */
  166. /* function pyramid(n) {
  167. for(let i = 1; i <= n; i++){
  168. let s = "";
  169. for(let j = 1; j<=(2*n -1); j++){
  170. (j>= n+1-i && j<= n-1+i) ? s+="#" : s+=".";
  171. }
  172. console.log(s);
  173. }
  174. }
  175. pyramid(+prompt("input number of tree rows", '')); */