main.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // switch:sizes------------------------------------------------------------------------------------;
  2. // let sizeOfDressUA = +prompt(
  3. // "Lets choose the right size for you. Enter your Ukrainian clothing size",
  4. // []
  5. // );
  6. // switch (sizeOfDressUA) {
  7. // case 38:
  8. // alert("Your international size is XXS");
  9. // break;
  10. // case 40:
  11. // alert("Your international size is XS");
  12. // break;
  13. // case 42:
  14. // alert("Your international size is S");
  15. // break;
  16. // case 44:
  17. // alert("Your international size is M");
  18. // break;
  19. // case 46:
  20. // alert("Your international size is L");
  21. // break;
  22. // case 48:
  23. // alert("Your international size is XL");
  24. // break;
  25. // case 50:
  26. // alert("Your international size is XXL");
  27. // break;
  28. // case 52:
  29. // alert("Your international size is 3XL");
  30. // break;
  31. // default:
  32. // alert("We do not know size of your dress");
  33. // }
  34. // switch:if-------------------------------------------------------------------------------------------;
  35. // let color = prompt("Enter color", "");
  36. // if (color === "red") {
  37. // document.write("<div style='background-color: red;'>Red</div>");
  38. // } else if (color === "black") {
  39. // document.write(
  40. // "<div style='background-color: black; color: white;'>Black</div>"
  41. // );
  42. // } else if (color === "blue") {
  43. // document.write("<div style='background-color: blue;'>Blue</div>");
  44. // } else if (color === "green") {
  45. // document.write("<div style='background-color: green;'>Green</div>");
  46. // } else {
  47. // document.write(
  48. // "<div style='background-color: gray;'>I don`t understand</div>"
  49. // );
  50. // }
  51. // prompt: or--------------------------------------------------------------------------------------------;
  52. // let yearOfBirth =
  53. // +prompt("Please, type year of your birth", []) ||
  54. // alert("You did not enter the date of Birth");
  55. // let currentYear = 2022;
  56. // let age = currentYear - yearOfBirth;
  57. // alert(age);
  58. // confirm: or this days----------------------------------------------------------------------------------;
  59. // confirm("Shopping?") || alert("You are crazy");
  60. // confirm: if this days-----------------------------------------------------------------------------------;
  61. // let answer = confirm("Shopping?");
  62. // if (answer === false) {
  63. // alert("You are crazy");
  64. // } else {
  65. // alert("Yoohooo");
  66. // }
  67. // triple prompt-------------------------------------------------------------------------------------------;
  68. // let name = prompt("Enter your name", []);
  69. // let surname = prompt("Enter your surname", []);
  70. // let patronymic = prompt("Enter your patronymic", []);
  71. // alert(`${surname}, ${name}, ${patronymic}`);
  72. // default: or-------------------------------------------------------------------------------------------;
  73. // let good_name = prompt("Enter your name", []) || "Ivan";
  74. // let good_surname = prompt("Enter your surname", []) || "Ivanov";
  75. // let good_patronymic = prompt("Enter your patronymic", []) || "Petrovych";
  76. // alert(`${good_surname}, ${good_name}, ${good_patronymic}`);
  77. // default: if-------------------------------------------------------------------------------------------;
  78. // let go_name = prompt("Enter your name", []);
  79. // let go_surname = prompt("Enter your surname", []);
  80. // let go_patronymic = prompt("Enter your patronymic", []);
  81. // if (go_name === null) {
  82. // go_name = "Ivan";
  83. // } else if (go_surname === null) {
  84. // go_surname = "Ivanov";
  85. // } else if (go_patronymic === null) {
  86. // go_surname = "Petrovych";
  87. // }
  88. // alert(`${go_surname}, ${go_name}, ${go_patronymic}`);
  89. // login and password-------------------------------------------------------------------------------------------;
  90. // let user_login = prompt("Enter your login");
  91. // let user_password = prompt("Enter your password");
  92. // if (user_login != "admin" || user_password != "qwerty") {
  93. // alert("Access denied");
  94. // } else if (user_login === "admin" && user_password === "qwerty") {
  95. // alert("Access success");
  96. // }
  97. // currency calc-------------------------------------------------------------------------------------------;
  98. // let money = prompt("usd or eur?", []);
  99. // switch (money) {
  100. // case "usd":
  101. // let currensy_exchange = 0.027;
  102. // let uah = prompt("Enter the amount in hryvnias");
  103. // let amount = uah * currensy_exchange;
  104. // alert(amount);
  105. // break;
  106. // case "eur":
  107. // let ecurrensy_exchange = 0.025;
  108. // let u_ah = prompt("Enter the amount in hryvnias");
  109. // let amo_unt = u_ah * ecurrensy_exchange;
  110. // alert(amo_unt);
  111. // break;
  112. // }
  113. // currency calc: improved-------------------------------------------------------------------------------------------;
  114. // let money = prompt("usd or eur?", []);
  115. // money = money.toLowerCase();
  116. // switch (money) {
  117. // case "usd":
  118. // let currensy_exchange = 38.4;
  119. // let uah = prompt("Enter the amount in hryvnias");
  120. // let amount = uah / currensy_exchange;
  121. // alert(amount);
  122. // break;
  123. // case "eur":
  124. // let ecurrensy_exchange = 39;
  125. // let u_ah = prompt("Enter the amount in hryvnias");
  126. // let amo_unt = u_ah / ecurrensy_exchange;
  127. // alert(amo_unt);
  128. // break;
  129. // }
  130. // currency calc: two rates-------------------------------------------------------------------------------------------;
  131. // let money = prompt("usd or eur?", []);
  132. // money = money.toLowerCase();
  133. // let buyOrSale = confirm("You want buy currensy?", []);
  134. // switch (money) {
  135. // case "usd":
  136. // let currensy_exchange = buyOrSale === true ? 39.8 : 38.4;
  137. // let uah = prompt("Enter the amount in hryvnias");
  138. // let amount = uah / currensy_exchange;
  139. // alert(amount);
  140. // break;
  141. // case "eur":
  142. // let ecurrensy_exchange = buyOrSale === true ? 40.4 : 39;
  143. // let u_ah = prompt("Enter the amount in hryvnias");
  144. // let amo_unt = u_ah / ecurrensy_exchange;
  145. // alert(amo_unt);
  146. // break;
  147. // }
  148. // currency calc: if-------------------------------------------------------------------------------------------;
  149. // let money = prompt("usd or eur?", []);
  150. // money = money.toLowerCase();
  151. // let buyOrSale = confirm("You want buy currensy?", []);
  152. // if (money === "usd") {
  153. // let currensy_exchange = buyOrSale === true ? 39.8 : 38.4;
  154. // let uah = prompt("Enter the amount in hryvnias");
  155. // let amount = uah / currensy_exchange;
  156. // alert(amount);
  157. // } else if (money === "eur") {
  158. // let ecurrensy_exchange = buyOrSale === true ? 40.4 : 39;
  159. // let u_ah = prompt("Enter the amount in hryvnias");
  160. // let amo_unt = u_ah / ecurrensy_exchange;
  161. // alert(amo_unt);
  162. // } else {
  163. // alert("Enter a valid currensy");
  164. // }
  165. // scissors-------------------------------------------------------------------------------------------;
  166. // let select = prompt("paper , scissors, stone");
  167. // let items = ["paper", "scissors", "stone"];
  168. // select = select.toLowerCase();
  169. // alert(`You choose a ${select}`);
  170. // select = select.toLowerCase();
  171. // let selectComputer = items[Math.floor(Math.random() * items.length)];
  172. // alert(`Robot choose a ${selectComputer}`);
  173. // if (select === selectComputer) {
  174. // alert("draw");
  175. // } else if (select === "stone") {
  176. // if (selectComputer === "scissors") {
  177. // alert("You are win");
  178. // } else {
  179. // alert("You are lose");
  180. // }
  181. // } else if (select === "paper") {
  182. // if (selectComputer === "stone") {
  183. // alert("You are win");
  184. // } else {
  185. // alert("You are lose");
  186. // }
  187. // }
  188. // if (select === "scissors") {
  189. // if (selectComputer === "stone") {
  190. // alert("You are lose");
  191. // } else {
  192. // alert("You are win");
  193. // }
  194. // } else "Renew game";
  195. // Задание на синий пояс-------------------------------------------------------------------------------------------;
  196. // let usd = {
  197. // buyUsd: 38.4,
  198. // saleUsd: 39.8,
  199. // };
  200. // let eur = {
  201. // buyEur: 39,
  202. // saleEur: 40.4,
  203. // };
  204. // let gbp = {
  205. // buyGbp: 46,
  206. // saleGbp: 48.5,
  207. // };
  208. // let money = prompt("usd, eur or gbp?", []);
  209. // money = money.toLowerCase();
  210. // let buyOrSale = confirm("You want to buy currensy?", []);
  211. // if (money === "usd") {
  212. // currency_exchange = buyOrSale === true ? usd.saleUsd : usd.buyUsd;
  213. // } else if (money === "eur") {
  214. // currency_exchange = buyOrSale === true ? eur.saleEur : eur.buyEur;
  215. // } else if (money === "eur") {
  216. // currency_exchange = buyOrSale === true ? gbp.saleGbp : gbp.buyGbp;
  217. // } else {
  218. // alert("We do noy know such a currency");
  219. // }
  220. // let hryvnias = prompt("How much hryvnias do you want to exchange?");
  221. // let amount = hryvnias / currency_exchange;
  222. // alert(`You will get ${amount} ${money}`);
  223. // real data-------------------------------------------------------------------------------------------;
  224. let user_choice = prompt("How many hryvnias you want exchange?", []);
  225. let rates = prompt("You want to buy usd, eur or gbp?", []);
  226. rates = rates.toUpperCase();
  227. getCurrencies();
  228. async function getCurrencies() {
  229. const response = await fetch("https://open.er-api.com/v6/latest/UAH");
  230. const data = await response.json();
  231. if (rates === "USD") {
  232. amount = data.rates.USD * user_choice;
  233. alert(`You will get ${amount} ${rates}`);
  234. } else if (rates === "EUR") {
  235. amount = data.rates.EUR * user_choice;
  236. alert(`You will get ${amount} ${rates}`);
  237. } else if (rates === "GBP") {
  238. amount = data.rates.GBP * user_choice;
  239. alert(`You will get ${amount} ${rates}`);
  240. } else {
  241. alert("We don`t know such currency");
  242. }
  243. }
  244. // Дополнительное задание-------------------------------------------------------------------------------------------;
  245. // Задание на черный пояс-------------------------------------------------------------------------------------------;