script.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. let a = 5;
  2. let b, c;
  3. console.log(b)
  4. b = a * 5;
  5. console.log(b)
  6. b = c = b / 2;
  7. console.log(b, c)
  8. //semicolon: error
  9. // b = a * c console.log(b)
  10. //semicolon: mistake
  11. //Number: age
  12. let ageU,
  13. date = new Date().getFullYear();
  14. do {
  15. ageU = prompt('Enter your age', '');
  16. if (ageU !== '' && ageU) {
  17. alert(`Год рождения: ${date - ageU}`);
  18. }
  19. } while (ageU == '' || ageU == null);
  20. //Number: temperature
  21. let tempCels = prompt('Enter tempereture', ''),
  22. tempFar = tempCels * 1.8 + 32;
  23. alert(`In fahrenheit: ${tempFar} `);
  24. //Number: divide
  25. let num1Input = document.querySelector('.num1'),
  26. num2Input = document.querySelector('.num2'),
  27. calculateBtn = document.querySelector('.btn'),
  28. outer = document.querySelector('.outer');
  29. calculateBtn.addEventListener('click', () => {
  30. let arg1 = +num1Input.value,
  31. arg2 = +num2Input.value;
  32. if (arg1 && arg2) {
  33. let res = arg1 / arg2;
  34. outer.textContent = `${Math.floor(res)}`;
  35. } else {
  36. outer.textContent = `Enter correct number`;
  37. }
  38. });
  39. //Number: odd
  40. let evenNumber = +prompt('Enter even number', '');
  41. if (typeof evenNumber === 'string') {
  42. console.log('This is string');
  43. } else if (typeof evenNumber === 'number' && !isNaN(evenNumber) && evenNumber) {
  44. console.log('This is number');
  45. if (evenNumber % 2) {
  46. do {
  47. alert('Выведите четное число');
  48. evenNumber = +prompt('Enter even number', '');
  49. } while (evenNumber % 2);
  50. } else {
  51. console.log('Odd number');
  52. }
  53. } else {
  54. console.log('other type of data');
  55. }
  56. //String: greeting
  57. let userName = prompt('Введите свое имя', '');
  58. alert(`Привет ${userName}`);
  59. //String: lexics
  60. let userMessage = prompt('Enter your message', '');
  61. if (userMessage.includes('хуй')) {
  62. alert(`Вы использовали нецензурное выражение с ${userMessage.indexOf('хуй')} по ${userMessage.indexOf('хуй') + 3} символы`)
  63. let userCensoredMessage = userMessage.replace(/хуй/gi, '***');
  64. console.log(userCensoredMessage);
  65. } else {
  66. console.log(userMessage);
  67. }
  68. // confirm
  69. let confirmData = confirm('Chose one of answers');
  70. console.log(confirmData);
  71. console.log(typeof confirmData);
  72. let userGender = confirm('Are you men?');
  73. if (userGender) {
  74. alert('You are a men');
  75. } else {
  76. alert('You are a women');
  77. }
  78. //Array: real
  79. const arrBooks = ['Война и мир', 'Доктор живаго', 'Идиот', 'Граф Монте-Кристо', 'Повесть временных лет'],
  80. arrAuto = ['Bmw', 'Kia', 'Lexus', 'Toyota', 'Chevrolet'],
  81. arrUsers = ['rom587', 'masha2', 'semen1999', 'serg2005'];
  82. // Array: booleans
  83. let boolAnswers = [];
  84. for (let i = 0; i < 7; i++) {
  85. let confirmAnswer = confirm('Are you men?');
  86. boolAnswers[i] = confirmAnswer;
  87. }
  88. console.log(boolAnswers);
  89. // Array: plus
  90. function arrPlus(arr) {
  91. arr[2] = arr[0] + arr[1];
  92. console.log(arr);
  93. }
  94. const numbers = [25, 2, 99, 86, 2, 3, 0, 7];
  95. arrPlus(numbers);
  96. arrPlus(arrBooks);
  97. function arrPlusT(arr) {
  98. arr[3] = arr[0] + arr[1] + arr[2];
  99. console.log(arr);
  100. }
  101. function arrPlusString(arr) {
  102. arr[3] = `${arr[0]} * ${arr[1]} * ${arr[2]}`;
  103. console.log(arr);
  104. }
  105. arrPlusString(arrBooks);
  106. //Object: real
  107. const user = {
  108. login: 'serg',
  109. password: 698547,
  110. id: 8965222222,
  111. email: 'serg@gmail.com'
  112. }
  113. const phone = {
  114. brand: 'Apple',
  115. model: 'Iphone 11',
  116. display: 6.1,
  117. core: 'A13'
  118. }
  119. // Object: change
  120. phone.brand = 'Samsung';
  121. phone['model'] = 'Galaxy s20';
  122. console.log(phone);
  123. user.login = 'Max777';
  124. user['id'] = 888224445;
  125. console.log(user);
  126. //Comparison if
  127. let age = +prompt("Сколько вам лет?", "");
  128. if (age > 0 && age < 18) {
  129. alert("школьник");
  130. }
  131. else {
  132. if (age < 30) {
  133. alert("молодеж");
  134. } else {
  135. if (age < 45) {
  136. alert("зрелость");
  137. } else {
  138. if (age < 60) {
  139. alert("закат");
  140. } else {
  141. if (age > 60) {
  142. alert("как пенсия?");
  143. } else {
  144. if (age <= 0) {
  145. alert("как родишься приходи");
  146. } else {
  147. alert("то ли киборг, то ли ошибка");
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. //Comparison: sizes
  155. let userSize = +prompt('Enter you waist coverage', '');
  156. if (userSize && !isNaN(userSize)) {
  157. if (userSize > 63 && userSize < 65) {
  158. alert(`${userSize} - XXS `);
  159. } else if (userSize > 66 && userSize < 69) {
  160. alert(`${userSize} - XS `);
  161. } else if (userSize > 70 && userSize < 74) {
  162. alert(`${userSize} - S `);
  163. } else if (userSize > 75 && userSize < 78) {
  164. alert(`${userSize} - M `);
  165. } else if (userSize > 79 && userSize < 83) {
  166. alert(`${userSize} - L `);
  167. } else if (userSize > 84 && userSize < 89) {
  168. alert(`${userSize} - XL `);
  169. } else if (userSize > 90 && userSize < 94) {
  170. alert(`${userSize} - XXL `);
  171. } else if (userSize > 95 && userSize < 97) {
  172. alert(`${userSize} - XL `);
  173. } else {
  174. alert('maybe stop eating');
  175. }
  176. }
  177. //Ternary
  178. confirm('Are you a men?') ? alert('You are men') : alert('You are women');
  179. //Синий пояс Number: flats
  180. function calculateEntranceandFloor(apartmentNumber, numberOfFloors, numberOfApartmentceFloor) {
  181. let apartForEntrance = numberOfFloors * numberOfApartmentceFloor;
  182. console.log(apartForEntrance);
  183. let apartEntrance = Math.ceil(apartmentNumber / apartForEntrance);
  184. console.log(apartEntrance);
  185. let apartmentFloor = Math.ceil(apartmentNumber / numberOfApartmentceFloor);
  186. console.log(apartmentFloor % numberOfFloors);
  187. if (!(apartmentFloor % numberOfFloors)) {
  188. console.log(`Floor - ${numberOfFloors} and Entrance - ${apartEntrance}` );
  189. } else {
  190. console.log(`Floor - ${apartmentFloor % numberOfFloors} and Entrance - ${apartEntrance}` );
  191. }
  192. }
  193. calculateEntranceandFloor( 5, 9, 4);