main.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // Additional task
  2. var additionalTask = prompt("switchSizes, switch:if, prompt:or, confirm: or this days, confirm: if this days, triple prompt, default: or, default: if, login and password, currency calc && currency calc: improved, currency calc: two rates, currency calc: if, target, blue belt assignment'")
  3. switch(additionalTask) {
  4. case 'switch:sizes' :
  5. let size = prompt('Enter your size', " ");
  6. switch(size) {
  7. case '40' : alert('Your size in Norvay 34 S');
  8. break;
  9. case '42' : alert('Your size in Norvay 36 M');
  10. break;
  11. case '44' : alert('Your size in Norvay 38');
  12. break;
  13. case '46' : alert('Your size in Norvay 40 L');
  14. break;
  15. case '48' : alert('Your size in Norvay 42');
  16. break;
  17. case '50' : alert('Your size in Norvay 44 XL');
  18. break;
  19. case '52' : alert('Your size in Norvay 46');
  20. break;
  21. case '54' : alert('Your size in Norvay 54 XXL');
  22. break;
  23. default : alert('Sorry but you size not included in our table');
  24. }
  25. break;
  26. case 'switch:if' :
  27. var color = prompt("Введите цвет","");
  28. if (color == "red") {
  29. document.write("<div style='background-color: red;'>красный</div>");
  30. document.write("<div style='background-color: black; color: white;'>черный</div>");
  31. }
  32. else if (color == "black") {
  33. document.write("<div style='background-color: black; color: white;'>черный</div>");
  34. }
  35. else if (color == "blue") {
  36. document.write("<div style='background-color: blue;'>синий</div>");
  37. document.write("<div style='background-color: green;'>зеленый</div>");
  38. }
  39. else if (color == "green"){
  40. document.write("<div style='background-color: green;'>зеленый</div>");
  41. }
  42. else{
  43. document.write("<div style='background-color: gray;'>Я не понял</div>");
  44. }
  45. break;
  46. case 'prompt:or' :
  47. var yearNow = 2020;
  48. var personYears;
  49. var howOldPerson = +prompt('Сколько вам лет') || alert('Error');
  50. var personYears = yearNow - howOldPerson;
  51. if(howOldPerson!=null) alert('You born in ' +personYears );
  52. break;
  53. case 'confirm: or this days' :
  54. var shoping = confirm('Shoping?') || alert('You are a caca');
  55. alert('You are the best');
  56. break;
  57. case 'confirm: if this days' :
  58. let soping = confirm('Shoping?');
  59. if (soping==false) {
  60. alert('You are a caca');
  61. }
  62. else {alert('You are the best');
  63. }
  64. break;
  65. case 'triple prompt' :
  66. var name = prompt("Enter you name", "");
  67. var surname = prompt("Enter you surname", "");
  68. var fathername = prompt("Enter you fathername", "");
  69. alert(name + ' ' + surname + ' ' + fathername);
  70. break;
  71. case 'default: or' :
  72. var name = prompt("Enter you name") || "Ivan";
  73. var surname = prompt("Enter you surname") || "Ivanov";
  74. var fatherName = prompt("Enter you fathername") || "Ivanovich";
  75. alert(surname + ' ' + name + ' ' + fatherName);
  76. break;
  77. case 'default: if' :
  78. var surnameOne = prompt("Enter you surname");
  79. var nameOne = prompt("Enter you name");
  80. var fatherNameOne = prompt("Enter you fathername");
  81. if (!surnameOne) { surnameOne = 'Ivanov'}
  82. if (!nameOne) {nameOne = 'Ivan'}
  83. if (!fatherNameOne) {fatherNameOne = 'Ivanovich'}
  84. alert(surnameOne + ' ' + nameOne + ' ' + fatherNameOne);
  85. break;
  86. case 'login and password' :
  87. var name = 'stas';
  88. var nameTwo = 'alex';
  89. var nameThree = 'pety';
  90. var passworld = 1234;
  91. var passworldTwo = 777;
  92. var passworldThree = 'qwerty'
  93. var loginName = prompt("Enter you name", "") || alert("Enter you name")
  94. var loginPassworld = prompt("Enter you passworld", "") || alert("Enter you passworld")
  95. if (name!==loginName && passworld==loginPassworld || nameTwo!==loginName && passworldTwo==loginPassworld || nameThree!==loginName && passworldThree==loginPassworld){
  96. alert("Wrong name")
  97. }
  98. else if(name==loginName && passworld!==loginPassworld || nameTwo==loginName && passworldTwo!==loginPassworld || nameThree==loginName && passworldThree!==loginPassworld ){
  99. alert('Passworld is wrong')
  100. }
  101. else if (name==loginName && passworld==loginPassworld || nameTwo==loginName && passworldTwo==loginPassworld || nameThree==loginName && passworldThree==loginPassworld){
  102. alert("Cam in")
  103. }
  104. else if (name!=loginName && passworld!=loginPassworld) {
  105. alert('anncorect name and passworld')
  106. }else {alert('Cansel')}
  107. break;
  108. case 'currency calc && currency calc: improved' :
  109. var сurrency = prompt("Enter you currency usd or eur").toLowerCase();
  110. switch(сurrency) {
  111. case "usd" : currency = 29
  112. break;
  113. case "eur" : currency = 33
  114. }
  115. var sum = + prompt("Enter the amount you want to transfer to UAH");
  116. var dubget = sum * currency
  117. alert(dubget)
  118. break;
  119. case 'currency calc: two rates' :
  120. var сurrency = prompt("Enter you currency usd or eur").toLowerCase();
  121. switch(сurrency) {
  122. case "usd" : currency = 29
  123. break;
  124. case "eur" : currency = 33
  125. }
  126. var sum = + prompt("Enter the amount you want to transfer");
  127. var dubget = confirm("Click OK if you want to sell or Cancel if you want to buy") ? dubgett = sum * currency : dubggett = sum / currency;
  128. alert(dubget)
  129. break;
  130. case 'currency calc: if' :
  131. var currencyUsd = 29;
  132. var currencyEur = 33
  133. var currencyOne = prompt("Enter you currency usd or eur").toLowerCase();
  134. var sum = + prompt("Enter the amount you want to transfer");
  135. var dubgett = confirm("Click OK if you want to sell or Cancel if you want to buy")
  136. if (currencyOne === "usd" && sum>0 && dubgett) { var summa = sum * currencyUsd}
  137. if (currencyOne === "usd" && sum>0 && !dubgett) {var summa = sum / currencyUsd}
  138. if (currencyOne === "eur" && sum>0 && dubgett) {var summa = sum * currencyEur}
  139. if (currencyOne === "eur" && sum>0 && !dubgett) {var summa = sum / currencyEur}
  140. alert(summa)
  141. break;
  142. case 'scissors' :
  143. var game = prompt("Choose one from rock, scissors, paper").toLowerCase();
  144. var enemy = Math.floor(Math.random()*3);
  145. if (enemy == 0) {enemy = "rock"}
  146. {if (enemy == "rock" && game == "paper") alert("You have won")}
  147. {if (enemy == "rock" && game == "rock") alert("Draw")}
  148. {if (enemy == "rock" && game == "scissors") alert("Opponent defeated")}
  149. if (enemy == 1) {enemy = "paper"}
  150. {if (enemy == "paper" && game == "paper") alert("Draw")}
  151. {if (enemy == "paper" && game == "rock") alert("Opponent defeated")}
  152. {if (enemy == "paper" && game == "scissors") alert("You have won")}
  153. if (enemy == 2 ) {enemy = "scissors"}
  154. {if (enemy == "scissors" && game == "paper") alert("Opponent defeated")}
  155. {if (enemy == "scissors" && game == "rock") alert("You have won")}
  156. {if (enemy == "scissors" && game == "scissors") alert("Draw")}
  157. break;
  158. case 'blue belt assignment' :
  159. var ratios = {
  160. usdSell: 25.6,
  161. eurSell: 29,
  162. usdBay: 27.8,
  163. eurBay: 31,
  164. }
  165. var currency = prompt("Enter you currency usd or eur").toLowerCase();
  166. var sum = +prompt("Enter the amount you want to transfer");
  167. let cashUsbSell = sum * ratios["usdSell"];
  168. let cashUsdBay = sum/ratios["usdBay"];
  169. let cashEurSell = sum * ratios["eurSell"];
  170. let cashEurBay = sum/ratios["eurBay"];
  171. if (currency == 'usd') confirm("Click OK if you want to sell or Cancel if you want to buy") ?alert("Your cash on sale is" + " " + cashUsbSell) : alert("Your cash from the purchase is" + " " + cashUsdBay);
  172. if (currency == 'eur') confirm("Click OK if you want to sell or Cancel if you want to buy") ?alert("Your cash on sale is" + " " + cashEurSell) : alert("Your cash from the purchase is" + " " + cashEurBay);
  173. break;
  174. case 'target' :
  175. // Написать программу которая будет склонять слово товар в зависимости от количества
  176. // товаров в корзине. Например 1 - товар, 4 - товара, 6 - товаров.
  177. var target = ['товар', 'товаров', 'товара']
  178. var number = + prompt("Введите количество товаров")
  179. tipe = Math.abs(number%100)
  180. var numbers = tipe%10
  181. if (tipe>10 && tipe<20 || numbers>4 && numbers<11) {
  182. alert(number + ' ' + target[1])
  183. }else if (numbers > 1 && numbers < 5) {
  184. alert(number + ' ' + target[2])
  185. }else if (numbers == 1) {
  186. alert(number + ' ' + target[0])
  187. }else if (numbers == 0 ) {alert(number + ' ' + target[1])}else {alert("error")}
  188. break;
  189. }