index.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. //SWITCH: SIZES -----------------------------------------------------------------------
  12. function switchSizes() {
  13. let size = +prompt("enter size to covert (Russia => USA )");
  14. switch (size) {
  15. case 40:
  16. alert("S");
  17. break;
  18. case 42:
  19. case 44:
  20. alert("M");
  21. break;
  22. case 46:
  23. case 48:
  24. alert("L");
  25. break;
  26. case 50:
  27. case 52:
  28. alert("XL");
  29. break;
  30. case 54:
  31. alert("XLL");
  32. break;
  33. default:
  34. alert("Incorrect size");
  35. }
  36. }
  37. //SWITCH: IF -----------------------------------------------------------------------
  38. function switchIF() {
  39. let color = prompt("Введите цвет", "");
  40. if (color == "red") {
  41. document.write("<div style='background-color: red;'>красный</div>");
  42. document.write("<div style='background-color: black; color: white;'>черный</div>");
  43. } else if (color == "black") {
  44. document.write("<div style='background-color: black; color: white;'>черный</div>");
  45. } else if (color == "blue") {
  46. document.write("<div style='background-color: blue;'>синий</div>");
  47. document.write("<div style='background-color: green;'>зеленый</div>");
  48. } else if (color == "green") {
  49. document.write("<div style='background-color: green;'>зеленый</div>");
  50. } else {
  51. document.write("<div style='background-color: gray;'>Я не понял</div>");
  52. }
  53. }
  54. //PROMPT: OR -----------------------------------------------------------------------
  55. function promptOR() {
  56. +prompt("How old are you") || alert("error: incorrect age");
  57. }
  58. //CONFIRM: OR THIS DAYS -----------------------------------------------------------------------
  59. function confirmOR() {
  60. confirm("шопинг?") || alert("ты - бяка");
  61. }
  62. //CONFIRM: IF THIS DAYS -----------------------------------------------------------------------
  63. function confirmIF() {
  64. let isShoping = confirm("шопинг?");
  65. if (isShoping === false) {
  66. alert("ты - бяка");
  67. }
  68. }
  69. //TRIPLE PROMPT -----------------------------------------------------------------------
  70. function triplePrompt() {
  71. let surname = prompt("Фамилия");
  72. let name = prompt("Имя");
  73. let patronymic = prompt("Отчество");
  74. alert(` ${surname} ${name} ${patronymic}`);
  75. }
  76. //DEFAULT: OR -----------------------------------------------------------------------
  77. function defaultOR() {
  78. let surname = prompt("Фамилия") || "Иванов";
  79. let name = prompt("Имя") || "Иван";
  80. let patronymic = prompt("Отчество") || "Иванович";
  81. alert(` ${surname} ${name} ${patronymic}`);
  82. }
  83. //DEFAULT: IF -----------------------------------------------------------------------
  84. function defaultIF() {
  85. let surname = prompt("Фамилия") || "Иванов";
  86. let name = prompt("Имя") || "Иван";
  87. let patronymic = prompt("Отчество") || "Иванович";
  88. if (!surname) {
  89. surname = "Иванов";
  90. }
  91. if (!name) {
  92. name = "Иван";
  93. }
  94. if (!surname) {
  95. patronymic = "Иванович";
  96. }
  97. alert(` ${surname} ${name} ${patronymic}`);
  98. }
  99. //LOGIN AND PASSWORD -----------------------------------------------------------------------
  100. function loginAndPassword() {
  101. while (true) {
  102. let login = prompt("login");
  103. if (login && login === "admin") {
  104. let password = prompt("password");
  105. if (password && password === "qwerty") {
  106. alert("successfull login");
  107. break;
  108. } else {
  109. alert("password is incorrect");
  110. continue;
  111. }
  112. } else {
  113. alert("login is incorrect");
  114. continue;
  115. }
  116. }
  117. }
  118. //CURRENCY CALC -----------------------------------------------------------------------
  119. function currencyCalc() {
  120. let currency = prompt("Enter currency to convert(usd/eur)");
  121. let rate = 1;
  122. let amount = +prompt("Amount to convert");
  123. switch (currency) {
  124. case "usd":
  125. rate = 26.2;
  126. break;
  127. case "eur":
  128. rate = 30;
  129. break;
  130. }
  131. if (amount && amount > 0) {
  132. alert(amount / rate).toFixed(3);
  133. } else {
  134. alert("error");
  135. }
  136. }
  137. //CURRENCY CALC: IMPROVED -----------------------------------------------------------------------
  138. function currencyCalcImp() {
  139. let currency = prompt("Enter currency to convert(usd/eur)").toLowerCase();
  140. let rate = 1;
  141. let amount = +prompt("Amount to convert");
  142. switch (currency) {
  143. case "usd":
  144. rate = 26.2;
  145. break;
  146. case "eur":
  147. rate = 30;
  148. break;
  149. }
  150. if (amount && amount > 0) {
  151. alert(amount / rate).toFixed(3);
  152. } else {
  153. alert("error");
  154. }
  155. }
  156. //CURRENCY CALC: TWO RATES -----------------------------------------------------------------------
  157. function currencyCalcTwo() {
  158. let selling = confirm("Convert on selling rates?");
  159. let currency = prompt("Enter currency to convert(usd/eur)").toLowerCase();
  160. let rate = 1;
  161. let amount = +prompt("Amount to convert");
  162. switch (currency) {
  163. case "usd":
  164. rate = selling ? 26.23 : 26.14;
  165. break;
  166. case "eur":
  167. rate = selling ? 29.99 : 29.83;
  168. break;
  169. }
  170. if (amount && amount > 0) {
  171. alert(amount / rate).toFixed(3);
  172. } else {
  173. alert("error");
  174. }
  175. }
  176. //CURRENCY CALC: IF -----------------------------------------------------------------------
  177. function currencyCalcIF() {
  178. let selling = confirm("Convert on selling rates?");
  179. let currency = prompt("Enter currency to convert(usd/eur)").toLowerCase();
  180. let rate = 1;
  181. let amount = +prompt("Amount to convert");
  182. if (selling) {
  183. if (currency === "usd") {
  184. rate = 26.23;
  185. }
  186. if (currency === "eur") {
  187. rate = 29.99;
  188. }
  189. } else {
  190. if (currency === "usd") {
  191. rate = 26.14;
  192. }
  193. if (currency === "eur") {
  194. rate = 29.83;
  195. }
  196. }
  197. if (amount && amount > 0) {
  198. alert(amount / rate).toFixed(3);
  199. } else {
  200. alert("error");
  201. }
  202. }
  203. //SCISSORS -----------------------------------------------------------------------
  204. function scissors() {
  205. let chose = prompt("Make ur choise").toLowerCase();
  206. let aiChose = "";
  207. let random = Math.random();
  208. if (random <= 0.33) {
  209. aiChose = "камень";
  210. } else if (aiChose <= 0.66) {
  211. aiChose = "ножницы";
  212. } else {
  213. aiChose = "бумага";
  214. }
  215. console.log(aiChose);
  216. if (chose === aiChose) {
  217. alert("ничья");
  218. } else if (
  219. (chose === "камень" && aiChose === "бумага") ||
  220. (chose === "бумага" && aiChose === "ножницы") ||
  221. (chose === "ножницы" && aiChose === "камень")
  222. ) {
  223. alert("You lose");
  224. } else {
  225. alert("You win");
  226. }
  227. }
  228. //ЗАДАНИЕ НА СИНИЙ ПОЯС -----------------------------------------------------------------------
  229. function blue() {
  230. let rates = {};
  231. let currency = prompt("Enter currency to convert(usd/eur)").toLowerCase();
  232. let amount = +prompt("Amount to convert");
  233. fetch("https://open.er-api.com/v6/latest/UAH")
  234. .then((res) => res.json())
  235. .then((data) => {
  236. rates["usd"] = data.rates.USD;
  237. rates["eur"] = data.rates.EUR;
  238. })
  239. .then(() => {
  240. if (amount && amount > 0) {
  241. alert((amount * rates[currency]).toFixed(3));
  242. } else {
  243. alert("error");
  244. }
  245. });
  246. }
  247. //ДОПОЛНИТЕЛЬНОЕ ЗАДАНИЕ -----------------------------------------------------------------------
  248. while (true) {
  249. let task = prompt("Enter task name or leave blank to stop", "").toLowerCase();
  250. if (task) {
  251. switch (task) {
  252. case "switch: sizes":
  253. switchSizes();
  254. break;
  255. case "switch: if":
  256. switchIF();
  257. break;
  258. case "prompt: or":
  259. promptOR();
  260. break;
  261. case "confirm: or this days":
  262. confirmOR();
  263. break;
  264. case "confirm: if this days":
  265. confirmIF();
  266. break;
  267. case "triple prompt":
  268. triplePrompt();
  269. break;
  270. case "default: if":
  271. defaultIF();
  272. break;
  273. case "default: or":
  274. defaultOR();
  275. break;
  276. case "login and password":
  277. loginAndPassword();
  278. break;
  279. case "currency calc":
  280. currencyCalc();
  281. break;
  282. case "currency calc: improved":
  283. currencyCalcImp();
  284. break;
  285. case "currency calc: two rates":
  286. currencyCalcTwo();
  287. break;
  288. case "currency calc: if":
  289. currencyCalcIF();
  290. break;
  291. case "scissors":
  292. scissors();
  293. break;
  294. case "задание на синий пояс":
  295. blue();
  296. break;
  297. case "задание на черный пояс":
  298. black();
  299. break;
  300. }
  301. } else {
  302. break;
  303. }
  304. }
  305. //ЗАДАНИЕ НА ЧЕРНЫЙ ПОЯС -----------------------------------------------------------------------
  306. function black() {
  307. let choise = prompt("Make ur choise").toLowerCase();
  308. let random = Math.random();
  309. (choise === "камень" && random <= 0.33) ||
  310. (choise === "ножницы" && random > 0.33 && random <= 0.66) ||
  311. (choise === "бумага" && random > 0.66)
  312. ? alert("ничья")
  313. : (choise === "камень" && random > 0.66) ||
  314. (choise === "ножницы" && random <= 0.33) ||
  315. (choise === "бумага" && random > 0.33 && random <= 0.66)
  316. ? alert("You lose")
  317. : alert("You win");
  318. }
  319. </script>
  320. </body>
  321. </html>