script2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. //while(true) {
  2. switch(prompt('input task name:', '')) {
  3. case 'switch: sizes':
  4. //switch: sizes
  5. let usSize = [
  6. {
  7. number: [6],
  8. men: 'S',
  9. woman:['XXS']
  10. },
  11. {
  12. number: [8, 10],
  13. men: 'M',
  14. woman:['XXS', 'XS']
  15. },
  16. {
  17. number: [12, 14],
  18. men: 'L',
  19. woman:['S', 'M']
  20. },
  21. {
  22. number: [16, 18],
  23. men: 'XL',
  24. woman:['L','XL']
  25. },
  26. {
  27. number: [20, 22],
  28. men: 'XXL',
  29. woman:['XXL', 'XXXL']
  30. },
  31. ]
  32. let rusSize = prompt('Введите НАШ формат размера для переводa на на Американский формат','')
  33. console.log(isNaN(rusSize))
  34. switch(!isNaN(rusSize) && +rusSize >= 40 && +rusSize <= 56) {
  35. case true:
  36. rusSize = +rusSize
  37. let flag = 0
  38. switch(rusSize % 2 !== 0) {
  39. case true:
  40. rusSize--
  41. flag++
  42. }
  43. for(let i = 0; i < usSize.length; i++) {
  44. let temp = usSize[i].number.findIndex(element => { return element === (rusSize - 34)})
  45. switch( temp >= 0) {
  46. case true:
  47. alert(`
  48. ${rusSize+flag}-й размер в американском формате:
  49. +---------------------------------------+
  50. Размер: ${usSize[i].number[temp]}
  51. Мужчины: ${usSize[i].men}
  52. Женщины: ${usSize[i].woman[temp]}
  53. +---------------------------------------+
  54. `)
  55. i = usSize.length
  56. break;
  57. default:
  58. continue;
  59. }
  60. }
  61. break;
  62. case false:
  63. alert('Неправильный размер.')
  64. break;
  65. }
  66. break;
  67. case 'switch: if':
  68. let color = prompt("Введите цвет","");
  69. // switch (color){
  70. // case "red": document.write("<div style='background-color: red;'>красный</div>");
  71. // case "black": document.write("<div style='background-color: black; color: white;'>черный</div>");
  72. // break;
  73. // case "blue": document.write("<div style='background-color: blue;'>синий</div>");
  74. // case "green": document.write("<div style='background-color: green;'>зеленый</div>");
  75. // break;
  76. // default: document.write("<div style='background-color: gray;'>Я не понял</div>");
  77. // }
  78. if(color === 'red') {
  79. document.write("<div style='background-color: red;'>красный</div>");
  80. document.write("<div style='background-color: black; color: white;'>черный</div>");
  81. } else if(color === 'blue') {
  82. document.write("<div style='background-color: blue;'>синий</div>");
  83. document.write("<div style='background-color: green;'>зеленый</div>");
  84. } else if(color === 'green') {
  85. document.write("<div style='background-color: green;'>зеленый</div>");
  86. } else if(color === 'black') {
  87. document.write("<div style='background-color: black; color: white;'>черный</div>");
  88. } else {
  89. document.write("<div style='background-color: gray;'>Я не понял</div>");
  90. }
  91. break;
  92. case 'prompt: or':
  93. let age = prompt('Введите свой возраст', '') || alert('Вы не ввели ничего!')
  94. if (age && isNaN(age) || age > 200 || age < 0){
  95. alert('Вы ввели неверные данные!')
  96. } else if(age){
  97. age = age = Math.trunc(Number(age))
  98. res = new Date().getFullYear() - age
  99. alert(`Исходя из введенного вами возраста вы родились в ${res}г. либо ${res-1}г.`)
  100. }
  101. break;
  102. case 'confirm: or this days':
  103. confirm('шоппинг') || alert('ты-бяка')
  104. break;
  105. case 'confirm: if this days':
  106. if(!confirm('шоппинг')) {
  107. alert('ты-бяка')
  108. }
  109. break;
  110. case 'triple prompt':
  111. let Name = prompt('your Name:','')
  112. let surname = prompt('your Surname:','')
  113. let patronymic = prompt('your Patronymic:','')
  114. alert(`${surname} ${Name} ${patronymic}`)
  115. break;
  116. case 'default: or':
  117. let defaultName = prompt('your Name:','') || 'Иван'
  118. let defaultSurname = prompt('your Surname:','') || 'Иванов'
  119. let defaultPatronymic = prompt('your Patronymic:','') || 'Иванович'
  120. alert(`${defaultSurname} ${defaultName} ${defaultPatronymic}`)
  121. break;
  122. case 'default: if':
  123. let NameIf = prompt('your Name:','')
  124. let surnameIf = prompt('your Surname:','')
  125. let patronymicIf = prompt('your Patronymic:','')
  126. if(NameIf) {
  127. NameIf = NameIf
  128. } else {
  129. NameIf = 'Ivan'
  130. }
  131. if(surnameIf) {
  132. surnameIf = surnameIf
  133. } else {
  134. surnameIf = 'Ivanov'
  135. }
  136. if (patronymicIf) {
  137. patronymicIf = patronymicIf
  138. } else {
  139. patronymicIf = 'Ivanovich'
  140. }
  141. alert(`"if else" to add default values:
  142. ${surnameIf} ${NameIf} ${patronymicIf}`)
  143. break;
  144. case 'login and password':
  145. if(prompt('login','') === 'admin') {
  146. alert('correct login')
  147. if(prompt('password','') === 'qwerty') {
  148. alert('correct password')
  149. } else {
  150. alert('wrong password')
  151. }
  152. } else {
  153. alert('wrong login')
  154. }
  155. break;
  156. case 'currency calc':
  157. function truncateFraction (number) {
  158. try {
  159. let strNum = String(number).split('.')
  160. if(strNum[1].length > 2) {
  161. strNum[1] = strNum[1].slice(0, 2)
  162. }
  163. return Number(strNum.join('.'))
  164. } catch (e) {
  165. return number
  166. }
  167. }
  168. let curr = prompt('type currency: "eur" or "usd"','')
  169. let transferLog = {
  170. initial: 'hrn',
  171. to: '',
  172. ratios: {
  173. sold: {
  174. usd: 0.032,
  175. eur: 0.037,
  176. setUsd: function(value) {
  177. this.usd = value
  178. },
  179. setEur: function(value) {
  180. this.eur = value
  181. }
  182. },
  183. bought: {
  184. usd: 0.033,
  185. eur: 0.038
  186. }
  187. }
  188. }
  189. if(curr) {
  190. // switch(curr.toLowerCase()) {
  191. // case 'eur':
  192. // transferLog.to = 'eur'
  193. // confirm('Sell press "Ok" | Buy press "Cancel"')? transferLog.curr = [transferLog.ratios['sold']['usd'], 'sold'] : transferLog.curr = [transferLog.ratios['bought']['usd'], 'bought']
  194. // break;
  195. // case 'usd':
  196. // transferLog.to = 'usd'
  197. // confirm('Sell press "Ok" | Buy press "Cancel"')? transferLog.curr = [transferLog.ratios['sold']['eur'], 'sold'] : transferLog.curr = [transferLog.ratios['bought']['eur'], 'bought']
  198. // break;
  199. // }
  200. if(curr.toLowerCase() === 'eur') {
  201. transferLog.to = 'eur'
  202. confirm('Sell press "Ok" | Buy press "Cancel"')? transferLog.curr = [transferLog.ratios['sold']['usd'], 'sold'] : transferLog.curr = [transferLog.ratios['bought']['usd'], 'bought']
  203. }
  204. if(curr.toLowerCase() === 'usd') {
  205. transferLog.to = 'usd'
  206. confirm('Sell press "Ok" | Buy press "Cancel"')? transferLog.curr = [transferLog.ratios['sold']['eur'], 'sold'] : transferLog.curr = [transferLog.ratios['bought']['eur'], 'bought']
  207. }
  208. if(transferLog.to === 'eur' || transferLog.to === 'usd') {
  209. transferLog.money = prompt('input amount of money to give', '')
  210. if(!+transferLog.money) {
  211. alert('invalid input')
  212. } else {
  213. transferLog.given = Number(transferLog.money)
  214. if(transferLog.curr[1] === 'sold') {
  215. transferLog.money = truncateFraction(transferLog.given / transferLog.curr[0])
  216. transferLog.message = `You've ${transferLog.curr[1]} ${transferLog.given}${transferLog.to} for ${transferLog.money}${transferLog.initial}`
  217. } else if(transferLog.curr[1] === 'bought') {
  218. transferLog.money = truncateFraction(transferLog.given * transferLog.curr[0])
  219. transferLog.message = `You've ${transferLog.curr[1]} ${transferLog.money}${transferLog.to} for ${transferLog.given}${transferLog.initial}`
  220. }
  221. transferLog.money > 0? alert(transferLog.message) : alert(`Looks like there is too little amount of hrn given to translate to ${transferLog.to}`)
  222. }
  223. } else {
  224. alert('invalid input')
  225. }
  226. } else {
  227. alert('No input.')
  228. }
  229. break;
  230. case 'scissors':
  231. let combos = {
  232. paper: {
  233. conter: 'scissors'
  234. },
  235. scissors: {
  236. conter: 'rock'
  237. },
  238. rock: {
  239. conter: 'paper'
  240. }
  241. }
  242. let user = prompt('rock, paper, scissors?').toLowerCase()
  243. if(user === 'rock' || user === 'paper' || user === 'scissors') {
  244. let computer = Math.random()
  245. if(computer >= 0.6) {
  246. computer = 'scissors'
  247. } else if(computer <= 0.3) {
  248. computer = 'paper'
  249. } else {
  250. computer = 'rock'
  251. }
  252. alert(`computer: ${computer}`)
  253. if(user === computer) {
  254. alert('TIE')
  255. } else {
  256. combos[computer].conter === user ? alert('USER WINS.') : alert('COMPUTER WINS.')
  257. }
  258. } else {
  259. alert('user disqualified! Compuer wins!')
  260. }
  261. break;
  262. default:
  263. alert('no matches found:(')
  264. break;
  265. }
  266. //}