/* 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);