123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- /* first part of home work with logical operations */
- /* first task for rewrite swtch to if */
- /* let color = prompt("Введите цвет","");
- if(color == 'red') {
- document.write("<div style='background-color: red;'>red</div>");
-
- }
- if(color == 'black') {
- document.write("<div style='background-color: black; color: white;'>black</div> ");
-
- }
- if(color == 'blue') {
- document.write("<div style='background-color: blue;'>blue</div> ");
-
- }
- if(color == 'green') {
- document.write("<div style='background-color: green;'>green</div> ");
-
- }
- if (color == "") {
- alert('Please input your color');
- }
- if (color == null) {
- alert('Please input your color');
- } */
- /* task 2 Age */
- /* let age = +prompt("Введите ваш возраст", "");
- debugger;
- if (age == false || age == null) {
- alert('You dont input your age');
- } */
- /* task 3 shopping */
- /* let answer = confirm("Shopping?");
- if (answer) {
- alert('Yeeeeaaaaaahhhhhhhh cool')
- } else {
- alert('You baka(((((((');
- } */
- /* task 4 Full_name */
- /* let namme = prompt("Введите свое имя", "");
- let surname = prompt("Введите свою фамилию","");
- let patronymic = prompt("Введите свое отчество", "");
- if(surname == "" || surname == null) {
- surname = 'Иванов';
- }
- if(namme =="" || namme == null) {
- namme = 'Ivan';
- }
- if (patronymic == "" || patronymic == null) {
- patronymic = 'Ivanovich';
- }
- alert(`${surname} ${namme} ${patronymic}`); */
- /* task login and password */
- /* let login = 'admin';
- let password = 'qwerty';
- let inputLogin = prompt("input your login", '');
- if(inputLogin === login) {
- let inputPassword = prompt("input your password", "");
- if (inputPassword === password) {
- alert('Succesful')
- }
- } else if(inputLogin === null || inputLogin === "") {
- alert('login incorrect try again');
- }
- */
- /* currency task */
- /*
- fetch('https://open.er-api.com/v6/latest/UAH').then(res => res.json())
- .then(data => {
- console.log(data.rates);
- let inputCurrency = prompt('input currency', "").toUpperCase();
- let inputValueTotransfer = +prompt('input value', "");
- for(let [key,value] of Object.entries(data.rates)){
- if(key == inputCurrency) {
- let result = (inputValueTotransfer*value).toFixed(2);
- console.log(result);
- alert(`You transfer ${inputValueTotransfer} UAH to ${result} ${inputCurrency}`)
- }
- }
- }) */
- /* 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 */
-
- /* let humanChoise = prompt("введите камень,ножницы,бумагу", "");
- let computerChoise = Math.floor(Math.random()*3) */
- /* let values = {
- 'Paper' : {
- 'Paper' : 'Ties with',
- 'Rock' : 'Beats',
- 'Scissors': 'Loses to'
- },
- 'Rock' : {
- 'Paper' : 'Loses to',
- 'Rock' : 'Ties with',
- 'Scissors': 'Beats'
- },
- 'Scissors' : {
- 'Paper' : 'Beats',
- 'Rock' : 'Loses to',
- 'Scissors': 'Ties with'
- }
- }
- let a = prompt("First sign?\n")
- let b = prompt("Second sign?\n")
- console.log(a, values[a][b], b, "!")
-
- увидел такое решение было интересно попробывать как будет работать, тут добавить рандомный выбор на строне б из массива вариантов и
- превести наверное все в ловер кейс или аппер значения особо это не поменяет, ниже вариант который мне больше по душе но как в одну строку вариантов не пришло в голову
- */
- function computerPlay() {
- let variants = ['rock', 'paper', 'scissors'];
- let rnd = Math.floor(Math.random()*3);
- return variants[rnd];
- }
- function playerPlay() {
- let playerChoise = prompt('input rock,paper,scissors', '').toLowerCase();
- return playerChoise;
- }
- let playerSelection = playerPlay();
- let computerSelection = computerPlay();
- function playGame(playerSelection, computerSelection) {
- console.log(playerSelection);
- console.log(computerSelection);
- if(playerSelection === computerSelection) {
- return alert('It is a tie');
- }
- if(playerSelection === 'rock') {
- if(computerSelection === 'scissors') {
- return alert('Player wins with rock');
- } else if(computerSelection === 'paper') {
- return alert('Computer wins with paper');
- }
- }
- if(playerSelection === 'paper') {
- if(computerSelection === 'rock') {
- alert('Player wins with paper');
- } else if(computerSelection === 'scissors') {
- alert('Computer wins with scissors');
- }
- }
- if(playerSelection === 'scissors') {
- if(computerSelection === "paper") {
- alert('Player wins with scissors');
- } else if(computerSelection === 'rock') {
- alert('Computer wins with rock');
- }
- }
- }
- playGame(playerSelection, computerSelection);
|