const btn = document.getElementById("play");
const player1 = document.getElementById("player1");
const player2 = document.getElementById("player2");
function getPlayerResult() {
let result = Math.floor((Math.random() * 3) + 1);
let num1 = result;
let num2 = result;
function getElemById() {
if (result == 1) {
result = 'Камень';
} else if (result == 2) {
result = 'Ножницы';
} else if (result == 3) {
result = 'Бумага';
}
}
function determineWinner(count1, count2) {
}
getElemById();
determineWinner(num1, num2);
return result;
}
function runGame() {
player1.innerHTML = getPlayerResult();
player2.innerHTML = getPlayerResult();
}
btn.addEventListener("click", runGame);
const player1 = document.getElementById('player1');
const player2 = document.getElementById('player2');
const resultElem = document.getElementById('result');
const btn = document.getElementById('play');
btn.addEventListener('click', runGame);
function getPlayerResult() {
const result = Math.floor(3 * Math.random());
return result;
}
function getNameById(id) {
let name = 'Error';
switch (id) {
case 0:
result = 'Rock';
break;
case 1:
result = 'Scissors';
break;
case 2:
result = 'Paper';
break;
}
return name;
}
function determineWinner(idFirst, idSecond) {
const result = (idSecond - idFirst + 3) % 3;
return result;
}
function getMessageByResult(result) {
let message = 'Error';
switch (id) {
case 0:
message = 'The game ended in a draw.';
break;
case 1:
message = 'The first player won.';
break;
case 2:
message = 'The second player won.';
break;
}
return message;
}
function runGame() {
const result1 = getPlayerResult();
const result2 = getPlayerResult();
player1.innerHTML = getNameById(result1);
player2.innerHTML = getNameById(result2);
const winner = determineWinner(result1, result2);
resultElem.innerHTML = getMessageByResult(winner);
}