hw2.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //**************1******************
  2. var color = prompt("Введите цвет", "");
  3. if (color == "red") {
  4. document.write("<div style='background-color: red;'>красный</div>");
  5. }
  6. else if (color == "black") {
  7. document.write("<div style='background-color: black; color: white;'>черный</div>");
  8. }
  9. else if (color == "blue") {
  10. document.write("<div style='background-color: blue;'>синий</div>");
  11. }
  12. else if (color == "green") {
  13. document.write("<div style='background-color: green;'>зеленый</div>");
  14. }
  15. else {
  16. document.write("<div style='background-color: gray;'>Я не понял</div>");
  17. }
  18. //**************2 and 4 and 5******************
  19. var age = prompt("enter your age", "");
  20. if (age => 0 && age <= 100) {
  21. alert("good work!");
  22. }
  23. else {
  24. alert("enter again");
  25. }
  26. alert("something");
  27. if (age <= 10) {
  28. alert("Привет сопля" + ",иди спать, детское время закончилось");
  29. }
  30. else if (age <= 20 && age > 10) {
  31. alert("Privet, хорошее время для прогулки");
  32. }
  33. else if (age <= 30 && age > 20) {
  34. alert("Приветсвую, хороший сегодня вечер");
  35. }
  36. else if (age <= 40 && age > 30) {
  37. alert("Здравствуйте, прекрасный вечер");
  38. }
  39. else if (age < 100 && age >= 50) {
  40. alert("Здравствуйте многоувожаемый старый мурдый человек, самое время для беседы");
  41. }
  42. //**************3******************
  43. let dec = 31, oct = 31, aug = 31, jul = 31, may = 31, march = 31, jan = 31, nov = 30, sept = 30, jun = 30, apr = 30,
  44. feb = 29;
  45. let month = prompt("choose the month");
  46. switch (month) {
  47. case "jan":
  48. alert("in January are " + jan + "days");
  49. break;
  50. case "feb":
  51. alert("in February are " + feb + "days");
  52. break;
  53. case "march":
  54. alert("in March are " + march + "days");
  55. break;
  56. case "apr":
  57. alert("in April are " + apr + "days");
  58. break;
  59. case "may":
  60. alert("in May are " + may + "days");
  61. break;
  62. case "jun":
  63. alert("in Jun are " + jun + "days");
  64. break;
  65. case "jul":
  66. alert("in July are " + jul + "days");
  67. break;
  68. case "aug":
  69. alert("in August are " + aug + "days");
  70. break;
  71. case "sept":
  72. alert("in September are " + sept + "days");
  73. break;
  74. case "nov":
  75. alert("in November are " + nov + "days");
  76. break;
  77. case "oct":
  78. alert("in October are " + oct + "days");
  79. break;
  80. case "dec":
  81. alert("in December are " + dec + "days");
  82. break;
  83. default:
  84. alert("try again");
  85. }
  86. //**************6******************
  87. var a = {
  88. tagName: 'body',
  89. subTags: b = {
  90. tagName: 'div',
  91. subTags: s = {
  92. tagName: 'span',
  93. text: 'Enter a data please'
  94. },
  95. subTags: br = {
  96. tagName: 'br',
  97. },
  98. subTags: input1 = {
  99. tagName: 'input',
  100. attrs: 'type=\'text\' id=\'name\''
  101. },
  102. subTags: input2 = {
  103. tagName: 'input',
  104. attrs: 'type=\'text\' id=\'surname\''
  105. }
  106. },
  107. subTags: c = {
  108. tagName: 'div',
  109. subTags: button1 = {
  110. tagName: 'button',
  111. text: 'OK',
  112. attrs: ' id=\'ok\''
  113. },
  114. subTags: button2 = {
  115. tagName: 'button',
  116. text: 'Cancel',
  117. attrs: ' id=\'cancel\''
  118. }
  119. }
  120. }
  121. //**************7******************
  122. var notebook = {
  123. brand: prompt("Enter a brand"),
  124. type: prompt("Enter a type"),
  125. model: prompt("Enter a model"),
  126. ram: prompt("Enter a ram"),
  127. size: prompt("Enter a size"),
  128. weight: prompt("Enter a weight"),
  129. resolution: {
  130. width: prompt("Enter a width"),
  131. height: prompt("Enter a height"),
  132. },
  133. };
  134. var phone = {
  135. brand: prompt("Enter a brand"),
  136. model: prompt("Enter a model"),
  137. ram: prompt("Enter a ram"),
  138. color: prompt("Enter a color"),
  139. };
  140. var person = {
  141. name: prompt("Enter a name"),
  142. surname: prompt("Enter a surname"),
  143. married: confirm("married?"),
  144. }
  145. //**************8******************
  146. do {
  147. var a = confirm("enter your choice");
  148. } while (a == false);
  149. //**************9******************
  150. let num = prompt("enter your number",);
  151. nextPrime:
  152. for (let i = 2; i <= num; i++) {
  153. for (let j = 2; j < i; j++) { // проверить, делится ли число..
  154. if (i % j == 0) continue nextPrime; // не подходит, берём следующее
  155. }
  156. alert(i); // простое число
  157. }
  158. //**************10******************
  159. for (let i = 0; true; i++) if (Math.random() > 0.9) {
  160. alert(++i);
  161. break;
  162. }
  163. //**************11******************
  164. let numb = prompt("enter number (it will chetnoe or nechotnoe)",);
  165. var a = '';
  166. for (var i = 0; i < numb; i++) {
  167. a += '#';
  168. }
  169. console.log(a);
  170. //**************12******************
  171. var numb = prompt("enter length of array",);
  172. var array = [];
  173. for (var i = 0; i < numb; i++) {
  174. array.push(Math.pow(i + 1, 3));
  175. }
  176. console.log(array);