main.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* first part of home work with logical operations */
  2. /* first task for rewrite swtch to if */
  3. /* let color = prompt("Введите цвет","");
  4. if(color == 'red') {
  5. document.write("<div style='background-color: red;'>red</div>");
  6. }
  7. if(color == 'black') {
  8. document.write("<div style='background-color: black; color: white;'>black</div> ");
  9. }
  10. if(color == 'blue') {
  11. document.write("<div style='background-color: blue;'>blue</div> ");
  12. }
  13. if(color == 'green') {
  14. document.write("<div style='background-color: green;'>green</div> ");
  15. }
  16. if (color == "") {
  17. alert('Please input your color');
  18. }
  19. if (color == null) {
  20. alert('Please input your color');
  21. } */
  22. /* task 2 Age */
  23. /* let age = +prompt("Введите ваш возраст", "");
  24. debugger;
  25. if (age == false || age == null) {
  26. alert('You dont input your age');
  27. } */
  28. /* task 3 shopping */
  29. /* let answer = confirm("Shopping?");
  30. if (answer) {
  31. alert('Yeeeeaaaaaahhhhhhhh cool')
  32. } else {
  33. alert('You baka(((((((');
  34. } */
  35. /* task 4 Full_name */
  36. /* let namme = prompt("Введите свое имя", "");
  37. let surname = prompt("Введите свою фамилию","");
  38. let patronymic = prompt("Введите свое отчество", "");
  39. if(surname == "" || surname == null) {
  40. surname = 'Иванов';
  41. }
  42. if(namme =="" || namme == null) {
  43. namme = 'Ivan';
  44. }
  45. if (patronymic == "" || patronymic == null) {
  46. patronymic = 'Ivanovich';
  47. }
  48. alert(`${surname} ${namme} ${patronymic}`); */
  49. /* task login and password */
  50. /* let login = 'admin';
  51. let password = 'qwerty';
  52. let inputLogin = prompt("input your login", '');
  53. if(inputLogin === login) {
  54. let inputPassword = prompt("input your password", "");
  55. if (inputPassword === password) {
  56. alert('Succesful')
  57. }
  58. } else if(inputLogin === null || inputLogin === "") {
  59. alert('login incorrect try again');
  60. }
  61. */
  62. /* currency task */
  63. /*
  64. fetch('https://open.er-api.com/v6/latest/UAH').then(res => res.json())
  65. .then(data => {
  66. console.log(data.rates);
  67. let inputCurrency = prompt('input currency', "").toUpperCase();
  68. let inputValueTotransfer = +prompt('input value', "");
  69. for(let [key,value] of Object.entries(data.rates)){
  70. if(key == inputCurrency) {
  71. let result = (inputValueTotransfer*value).toFixed(2);
  72. console.log(result);
  73. alert(`You transfer ${inputValueTotransfer} UAH to ${result} ${inputCurrency}`)
  74. }
  75. }
  76. }) */
  77. /* i don`t know i am need make sold or buying for others currency. I know how to make that better but that take more time for realise */
  78. /* let humanChoise = prompt("введите камень,ножницы,бумагу", "");
  79. let computerChoise = Math.floor(Math.random()*3) */
  80. /* let values = {
  81. 'Paper' : {
  82. 'Paper' : 'Ties with',
  83. 'Rock' : 'Beats',
  84. 'Scissors': 'Loses to'
  85. },
  86. 'Rock' : {
  87. 'Paper' : 'Loses to',
  88. 'Rock' : 'Ties with',
  89. 'Scissors': 'Beats'
  90. },
  91. 'Scissors' : {
  92. 'Paper' : 'Beats',
  93. 'Rock' : 'Loses to',
  94. 'Scissors': 'Ties with'
  95. }
  96. }
  97. let a = prompt("First sign?\n")
  98. let b = prompt("Second sign?\n")
  99. console.log(a, values[a][b], b, "!")
  100. увидел такое решение было интересно попробывать как будет работать, тут добавить рандомный выбор на строне б из массива вариантов и
  101. превести наверное все в ловер кейс или аппер значения особо это не поменяет, ниже вариант который мне больше по душе но как в одну строку вариантов не пришло в голову
  102. */
  103. function computerPlay() {
  104. let variants = ['rock', 'paper', 'scissors'];
  105. let rnd = Math.floor(Math.random()*3);
  106. return variants[rnd];
  107. }
  108. function playerPlay() {
  109. let playerChoise = prompt('input rock,paper,scissors', '').toLowerCase();
  110. return playerChoise;
  111. }
  112. let playerSelection = playerPlay();
  113. let computerSelection = computerPlay();
  114. function playGame(playerSelection, computerSelection) {
  115. console.log(playerSelection);
  116. console.log(computerSelection);
  117. if(playerSelection === computerSelection) {
  118. return alert('It is a tie');
  119. }
  120. if(playerSelection === 'rock') {
  121. if(computerSelection === 'scissors') {
  122. return alert('Player wins with rock');
  123. } else if(computerSelection === 'paper') {
  124. return alert('Computer wins with paper');
  125. }
  126. }
  127. if(playerSelection === 'paper') {
  128. if(computerSelection === 'rock') {
  129. alert('Player wins with paper');
  130. } else if(computerSelection === 'scissors') {
  131. alert('Computer wins with scissors');
  132. }
  133. }
  134. if(playerSelection === 'scissors') {
  135. if(computerSelection === "paper") {
  136. alert('Player wins with scissors');
  137. } else if(computerSelection === 'rock') {
  138. alert('Computer wins with rock');
  139. }
  140. }
  141. }
  142. playGame(playerSelection, computerSelection);