script.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. let exersice = prompt("Chose exersice: \n switch: sizes - 1 \n switch: if - 2 \n prompt: or - 3 \n confirm: or this days - 4 \n confirm: if this days - 5\n triple prompt + default: or - 6 \n default: if - 7 \n login and password - 8 \n currency calc + currency calc: improved + currency calc: two rates - 9\n corrency calc: if - 10 \n scissors - 11 \n blue belt - 12 \n black belt - 13" )
  2. switch (exersice){
  3. case "1": searchSize(); break;
  4. case "2": color(); break;
  5. case "3": year(); break;
  6. case "4": Shopping(); break;
  7. case "5": ShoppingIf(); break;
  8. case "6": yourName(); break;
  9. case "7": yourNameSecond(); break;
  10. case "8": Log(); break;
  11. case "9": currencyCalc(); break;
  12. case "10": currencyCalc2(); break;
  13. case "11": scissors(); break;
  14. case "12": blueBelt(); break;
  15. case "13": blackBelt(); break;
  16. default: alert("Error. Try again")
  17. }
  18. //////
  19. ////switch: sizes 1
  20. function searchSize (styleWear, firstMassive, firstSize) {
  21. sizeWear = {
  22. russia: [40, 42, 44, 46, 48, 50, 52, 54],
  23. USA: ["S", "M", "M", "L", "L", "XL", "XL", "XXL"]
  24. }
  25. womanSize = {
  26. russia: [42 ,44, 46, 48, 50, 52, 54, 56],
  27. USA: ["XXS", "XS", "S", "M", "L", "XL", "XXL", "XXXL"]
  28. }
  29. sizeStockings = {
  30. russia: [21, 21, 23, 23, 25, 25, 27],
  31. USA: [8, 8.5, 9, 9.5, 10, 10.5, 11]
  32. }
  33. styleWear = prompt("What size chart do you need?(dress/outerwear/pants - 1, lingerie - 2, tights/stockings - 3", "");
  34. switch (styleWear) {
  35. case "1": styleWear = sizeWear, firstMassive = sizeWear.russia; break;
  36. case "2": styleWear = womanSize, firstMassive = womanSize.russia; break;
  37. case "3": styleWear = sizeStockings, firstMassive = sizeStockings.russia; break;
  38. default: alert ("Error. Please try again");
  39. return
  40. }
  41. firstSize = +prompt("Please give me your size in Russia/Urkaine style");
  42. firstSize = firstMassive.indexOf(firstSize)
  43. if (firstSize == -1) {
  44. return alert("Error. Please check your data")
  45. }
  46. alert ("Your size in USA chart is " + styleWear.USA[firstSize])
  47. }
  48. // searchSize()
  49. ///////
  50. //////
  51. ////switch: if 2
  52. function color() {
  53. let color = prompt("Введите цвет","");
  54. if (color === "red") {
  55. document.write("<div style='background-color: red;'>красный</div>")
  56. document.write("<div style='background-color: black; color: white;'>черный</div>")
  57. } else if (color === "black") {
  58. document.write("<div style='background-color: black; color: white;'>черный</div>")
  59. } else if (color === "blue") {
  60. document.write("<div style='background-color: blue;'>синий</div>")
  61. document.write("<div style='background-color: green;'>зеленый</div>")
  62. } else if ( color === "green") {
  63. document.write("<div style='background-color: green;'>зеленый</div>")
  64. }
  65. else {
  66. document.write("<div style='background-color: gray;'>Я не понял</div>")
  67. }
  68. }
  69. // color()
  70. ////////
  71. ///////
  72. ///prompt: or 3
  73. function year (yearBorn) {
  74. var today = new Date();
  75. var year = today.getFullYear();
  76. yearBorn = + prompt ("How old are you?");
  77. if (yearBorn == null || yearBorn == undefined || isNaN(yearBorn) || yearBorn == false) {
  78. return alert("Error. Please try again")
  79. } else {
  80. yearBorn = year - yearBorn;
  81. return alert ("The year when you're born is " + yearBorn)
  82. }
  83. }
  84. // year()
  85. ////////
  86. /////
  87. //confirm: or this days 4
  88. function Shopping() {
  89. (confirm ("Шопинг?")) ? alert("Уиии") : alert("Ты - бяка")
  90. }
  91. // Shopping()
  92. //////
  93. ///////
  94. //confirm: if this days 5
  95. function ShoppingIf (answer) {
  96. answer = confirm("Шопинг?")
  97. if (answer === false) {
  98. return alert("ты-бяка")
  99. } else {
  100. return alert ("Уиии")
  101. }
  102. }
  103. // ShoppingIf()
  104. ////////
  105. ////////
  106. //triple prompt
  107. //default: or 6
  108. function yourName (surname, name, yourFather) {
  109. surname = prompt ("Напишите, пожалуйста, вашу фамилию")
  110. surname = surname ? surname : "Хренова"
  111. name = prompt("Напишите, пожалуйста, как вас зовут.")
  112. name = name ? name : "Гадя"
  113. yourFather = prompt ("Напишите, пожалуйста, ваше отчество")
  114. yourFather = yourFather ? yourFather : "Петрович"
  115. return alert ("Здравствуйте, " + name + " " + yourFather + " " + surname)
  116. }
  117. // yourName()
  118. ////////
  119. /////////
  120. //defaut if 7
  121. function yourNameSecond (surname, name, yourFather) {
  122. question1 = prompt ("Напишите, пожалуйста, вашу фамилию")
  123. if (question1 === null || question1 === "") {
  124. surname = "Хренова"
  125. } else { surname = question1}
  126. question2 = prompt("Напишите, пожалуйста, как вас зовут.")
  127. if (question2 === null || question2 === "") {
  128. name = "Гадя"
  129. } else { name = question2 }
  130. question3 = prompt ("Напишите, пожалуйста, ваше отчество")
  131. if (question3 === null || question3 === "") {
  132. yourFather = "Петрович"
  133. } else { yourFather = question3 }
  134. return alert ("Здравствуйте, " + name + " " + yourFather + " " + surname)
  135. }
  136. // yourNameSecond()
  137. //////////
  138. ////////
  139. //login and password 8
  140. function Log (yourLog, yourPass) {
  141. let login = "admin";
  142. let password = "qwerty";
  143. yourLog = prompt ("Please write correct login")
  144. if (yourLog === login){
  145. yourPass = prompt ("Please write correct password")
  146. if (yourPass === password) {
  147. alert ("Congratulations! You're in.")
  148. } else {
  149. alert ("Error. The password is wrong. Please try again")
  150. }
  151. } else {
  152. return alert ("Error. The login is wrong. Please try again")
  153. }
  154. }
  155. // Log()
  156. //////////
  157. //////////
  158. ///currency calc
  159. ////currency calc: improved
  160. ////currency calc: two rates 9
  161. function currencyCalc (yourChoise, yourCount, result) {
  162. let usd = [28.31, 28.39];
  163. let eur = [33, 33.44];
  164. yourChoise = prompt("Please chose usd or eur.").toLowerCase();
  165. switch (yourChoise) {
  166. case "usd":yourChoise = usd; break;
  167. case "eur":yourChoise = eur; break;
  168. default: alert ("Error. Please try again");
  169. return
  170. }
  171. confirm ("If you want to buy click on 'ok' and on 'cancel' if want to sell") ? yourChoise = yourChoise[0] : yourChoise = yourChoise[1];
  172. yourCount = prompt("How much?");
  173. result = yourCount * yourChoise;
  174. (isNaN(result) ? alert ("Error. Please check your data") : alert ("Your result is " + result))
  175. }
  176. // currencyCalc()
  177. /////////
  178. ///////
  179. //currency calc: if 10
  180. function currencyCalc2 (yourChoise, yourCount, BuySell, result) {
  181. let usd = [28.31, 28.39];
  182. let eur = [33, 33.44];
  183. yourChoise = prompt("Please chose usd or eur.").toLowerCase();
  184. if (yourChoise == "usd") {
  185. yourChoise = usd
  186. } else if ( yourChoise == "eur") {
  187. yourChoise = eur
  188. } else {
  189. return alert("Error. Please try again")
  190. }
  191. BuySell = confirm ("If you want to buy click on 'ok' and on 'cancel' if want to sell")
  192. if (BuySell === true) {
  193. yourChoise = yourChoise[0]
  194. } else {
  195. yourChoise = yourChoise[1]
  196. }
  197. yourCount = prompt("How much?");
  198. if (isNaN(yourCount)) {
  199. return alert ("Error. Please cheack your data")
  200. } else {
  201. result = yourCount * yourChoise;
  202. return alert ("Your result is " + result)
  203. }
  204. }
  205. // currencyCalc2()
  206. ////////
  207. ///////
  208. //scissors 11
  209. function scissors (yourMove, myMove){
  210. let tools = ["rock", "scissors", "paper"];
  211. yourMove = prompt("Your move. Chose rock, scissors or paper").toLowerCase();
  212. myMove = tools[Math.floor(Math.random() * tools.length)];
  213. if (yourMove === myMove) {
  214. return alert("Dead heat")
  215. } else if (yourMove == "rock"&& myMove == "scissors" || yourMove == "scissors"&& myMove == "paper" || yourMove == "paper"&& myMove == "rock" ) {
  216. return alert ("Congratulations. You're win")
  217. } else {
  218. return alert ("Sorry. You're lose")
  219. }
  220. }
  221. // scissors()
  222. /////////
  223. //////
  224. ///Задание на синий пояс 12
  225. function blueBelt() {
  226. fetch('https://api.exchangeratesapi.io/latest')
  227. .then(res => res.json())
  228. .then(d => {
  229. let yourChoisefirst = prompt("What do you want yo sell?").toUpperCase();
  230. (yourChoisefirst === "EUR") ? yourChoisefirst = 1 : yourChoisefirst = (1 / d.rates[yourChoisefirst]);
  231. let yourChoisesecond = prompt("What do you want to buy?").toUpperCase();
  232. (yourChoisesecond === "EUR") ? yourChoisesecond = 1 : yourChoisesecond = (1 / d.rates[yourChoisesecond]);
  233. let count = prompt("How much?");
  234. let howMuch = (yourChoisefirst / yourChoisesecond * count).toFixed(2);
  235. if (isNaN(howMuch)) {
  236. return alert ("Error. Please check your data")
  237. } else {
  238. return alert(howMuch)
  239. }
  240. })
  241. }
  242. // blueBelt()
  243. ////
  244. //////
  245. ///Черный пояс 13
  246. function blackBelt (yourMove, myMove){
  247. let tools = ["rock", "scissors", "paper"];
  248. yourMove = prompt("Your move. Chose rock, scissors or paper").toLowerCase();
  249. myMove = tools[Math.floor(Math.random() * tools.length)];
  250. (yourMove === "rock" || yourMove === "paper" || yourMove === "scissors") ? ((yourMove === myMove) ? alert ("Dead heat") : (yourMove == "rock"&& myMove == "scissors" || yourMove == "scissors"&& myMove == "paper" || yourMove == "paper"&& myMove == "rock" ) ? alert("You're win") : alert ("You're lose")) : alert ("Error. Try again")
  251. }
  252. // blackBelt()
  253. //////