Js-HW3.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. let task = prompt('enter task name').toLowerCase();
  2. switch (task) {
  3. case 'switch: sizes':
  4. let size = +prompt('введите размер обуви дял конвертации в UK')
  5. switch (size) {
  6. case 35:
  7. alert(3.5);
  8. break;
  9. case 36:
  10. alert(4);
  11. break;
  12. case 37:
  13. alert(5);
  14. break;
  15. case 38:
  16. alert(6);
  17. break;
  18. case 39:
  19. alert(6.5);
  20. break;
  21. case 40:
  22. alert(7);
  23. break;
  24. default:
  25. alert('something went wrong')
  26. }
  27. break;
  28. case 'switch: if':
  29. let color = prompt("Введите цвет","");
  30. if(color === "red") {
  31. document.write("<div style='background-color: red;'>красный</div>")
  32. } else if(color === "black") {
  33. document.write("<div style='background-color: black; color: white;'>черный</div>")
  34. } else if(color === "blue") {
  35. document.write("<div style='background-color: blue;'>синий</div>")
  36. } else if(color === "green") {
  37. document.write("<div style='background-color: green;'>зеленый</div>")
  38. } else {
  39. document.write("<div style='background-color: gray;'>Я не понял</div>")
  40. }
  41. break;
  42. case 'prompt: or':
  43. let age1 = prompt('how old are you?');
  44. if(age1 === '' || age1 === null) {
  45. alert('something is wrong...')
  46. } else {
  47. alert(`you were born in ${2022 - age1}`)
  48. }
  49. break;
  50. case 'confirm: or this days':
  51. let question1 = confirm('Шоппинг?') || alert(' Ты - бяка!');
  52. break;
  53. case 'confirm: if this days':
  54. let question2 = confirm('Шоппинг?');
  55. if(!question2) {
  56. alert(' Ты - бяка!')
  57. }
  58. break;
  59. case 'triple prompt':
  60. let surname = prompt('Enter surname')
  61. let name = prompt('Enter name')
  62. let patronymic = prompt('Enter patronymic')
  63. alert(`${surname} ${name} ${patronymic}`)
  64. break;
  65. case 'default: or':
  66. let enteredName = prompt('enter your name');
  67. let enteredSurname = prompt('enter your surname');
  68. enteredName = enteredName || 'Ivan';
  69. enteredSurname = enteredSurname || 'Ivanov';
  70. break;
  71. case 'default: if':
  72. let enteredName2 = prompt('enter your name');
  73. let enteredSurname2 = prompt('enter your surname');
  74. if(!enteredSurname2) {
  75. enteredSurname2 = 'Ivanov'
  76. }
  77. if(!enteredName2) {
  78. enteredName2 = 'Ivan'
  79. }
  80. break;
  81. case 'login and password':
  82. const adminName = 'admin';
  83. const adminPassword = 'qwerty';
  84. let login = prompt('Login: ');
  85. if(adminName === login) {
  86. let password = prompt('Password: ');
  87. if(adminPassword === password) {
  88. alert('Success!')
  89. } else {
  90. alert('password is incorrect')
  91. }
  92. } else {
  93. alert('login is incorrect')
  94. }
  95. break;
  96. case 'currency calc':
  97. let currency1 = prompt('USD or EUR?')
  98. let rate1;
  99. switch (currency1) {
  100. case 'usd':
  101. rate1 = 34.67
  102. break;
  103. case 'eur':
  104. rate1 = 37.38
  105. break;
  106. default:
  107. rate1 = 0;
  108. }
  109. let uah = +prompt('enter UAH to convert');
  110. alert(`${(uah / rate1).toFixed(2)} ${currency1}`)
  111. break;
  112. case 'currency calc: improved':
  113. let currency2 = prompt('USD or EUR?').toLowerCase();
  114. let rate2;
  115. switch (currency2) {
  116. case 'usd':
  117. rate2 = 34.67
  118. break;
  119. case 'eur':
  120. rate2 = 37.38
  121. break;
  122. default:
  123. rate2 = 0;
  124. }
  125. let uah1 = +prompt('enter UAH to convert');
  126. alert(`${(uah1 / rate2).toFixed(2)} ${currency2}`)
  127. break;
  128. case 'currency calc: two rates':
  129. let currency3 = prompt('Do you want to use USD or EUR?').toLowerCase()
  130. let rate3;
  131. let buyRate1 = confirm('Do you want to buy currency?')
  132. switch (currency3) {
  133. case 'usd':
  134. buyRate1 ? rate3 = 36.28 : rate3 = 34.67
  135. break;
  136. case 'eur':
  137. buyRate1 ? rate3 = 41.77 : rate3 = 37.38
  138. break;
  139. default:
  140. alert('error');
  141. }
  142. let uah2 = +prompt('enter UAH to convert');
  143. alert(`${(uah2 / rate3).toFixed(2)} ${currency3}`)
  144. break;
  145. case 'currency calc: if':
  146. let currency4 = prompt('Do you want to use USD or EUR?').toLowerCase()
  147. if(currency4 === 'usd' || currency4 === 'eur') {
  148. let uah4 = +prompt('enter UAH to convert');
  149. let rate4;
  150. let buyRate2 = confirm('Do you want to buy currency?')
  151. if (currency4 === 'usd') {
  152. buyRate2 ? rate4 = 36.28 : rate4 = 34.67
  153. } else if (currency4 === 'eur') {
  154. buyRate2 ? rate4 = 41.77 : rate4 = 37.38
  155. } else {
  156. alert('error')
  157. }
  158. alert(`${(uah4 / rate4).toFixed(2)} ${currency4}`)
  159. }
  160. break;
  161. case 'scissors':
  162. let usersTurn = prompt('Rock, paper or scissors?').toLowerCase();
  163. let turns = ['rock', 'paper', 'scissors'];
  164. const randomIndex = Math.floor(Math.random() * 3)
  165. let computersTurn = turns[randomIndex]
  166. console.log(computersTurn)
  167. if(usersTurn === computersTurn) {
  168. alert('It\'s a tie!')
  169. } else if(usersTurn === 'paper' && computersTurn === 'scissors') {
  170. alert('computer won');
  171. } else if(usersTurn === 'scissors' && computersTurn === 'rock') {
  172. alert('computer won');
  173. } else if(usersTurn === 'rock' && computersTurn === 'paper') {
  174. alert('computer won')
  175. } else if(computersTurn === 'paper' && usersTurn === 'scissors') {
  176. alert('you won');
  177. } else if(computersTurn === 'scissors' && usersTurn === 'rock') {
  178. alert('you won');
  179. } else if(computersTurn === 'rock' && usersTurn === 'paper') {
  180. alert('you won')
  181. } else {
  182. alert('error')
  183. }
  184. break;
  185. case 'задание на синий пояс':
  186. let ratios = {
  187. usdToBuy: 36.28,
  188. eurToBuy: 41.77,
  189. usdToSell: 34.67,
  190. eurToSell: 37.38
  191. }
  192. let currency5 = prompt('Do you want to use USD or EUR?').toLowerCase()
  193. if(currency5 === 'usd' || currency5 === 'eur') {
  194. let rate;
  195. let uah = +prompt('enter UAH to convert');
  196. let buyRate = confirm('Do you want to buy currency?')
  197. if (currency5 === 'usd') {
  198. rate = buyRate ? ratios["usdToBuy"] : ratios["usdToSell"]
  199. } else if (currency5 === 'eur') {
  200. rate = buyRate ? ratios["eurToBuy"] : ratios["eurToSell"]
  201. } else {
  202. alert('error')
  203. }
  204. alert(`${(uah / rate).toFixed(2)} ${currency5}`)
  205. }
  206. break;
  207. case 'real data':
  208. let currency = prompt('Enter the currency name to convert (e.g. USD)').toUpperCase()
  209. let uah3 = +prompt('enter UAH to convert');
  210. fetch('https://open.er-api.com/v6/latest/' + currency)
  211. .then(res => res.json())
  212. .then(data => {
  213. alert(`${(uah3 / data.rates.UAH).toFixed(2)} ${currency}`)
  214. })
  215. break;
  216. case 'задание на черный пояс':
  217. let usersTurn1 = prompt('Rock, paper or scissors?').toLowerCase();
  218. let turns1 = ['rock', 'paper', 'scissors'];
  219. const randomIndex1 = Math.floor(Math.random() * 3)
  220. let computersTurn1 = turns1[randomIndex1]
  221. console.log(computersTurn1)
  222. let compWin = usersTurn1 === 'paper' && computersTurn1 === 'scissors' || usersTurn1 === 'scissors' && computersTurn1 === 'rock' || usersTurn1 === 'rock' && computersTurn1 === 'paper';
  223. let userWin = computersTurn1 === 'paper' && usersTurn1 === 'scissors' || computersTurn1 === 'scissors' && usersTurn1 === 'rock' || computersTurn1 === 'rock' && usersTurn1 === 'paper';
  224. let tie = usersTurn1 === computersTurn1 && alert('It\'s a tie!')
  225. let victory = compWin && alert('computer won') || userWin && alert('you won');
  226. break;
  227. };