Skip to content

Commit

Permalink
Tested live
Browse files Browse the repository at this point in the history
  • Loading branch information
Giolii committed Apr 19, 2024
1 parent 43a5f70 commit ef346b1
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@ function getComputerChoice() { //Computer picks rock, paper or scissor
return choices[Math.floor(Math.random() * choices.length)];
}


function playGame(){ //Play 5 games
const result = playRound(playerSelection, computerSelection);
console.log(result); // Log the result to the console
if (mac + player === 5 && mac > player) {
console.log(`You lose! Mac points:${mac}, Player points:${player}`);
// break;
} else if (mac + player === 5 && mac < player){
console.log(`You win! Player points:${player}, Mac points:${mac}.`);
// break;
}
}

function playRound(playerSelection,computerSelection){
let tie = `TIE! ${playerSelection} and ${computerSelection}`;
let win = `Yes, ${playerSelection} beats ${computerSelection}.`;
let lose= `No, ${computerSelection} beats ${playerSelection}.`;
let tie = `TIE! ${playerSelection} and ${computerSelection}.`;
let win = `YES, ${playerSelection} beats ${computerSelection}.`;
let lose= `NO, ${computerSelection} beats ${playerSelection}.`;
const macWin = `You LOSE! Mac points:${mac}, Player points:${player}.`;
const playerWin = `You WIN! Player points:${player} Mac points:${mac}.`;

if (mac === 5) return macWin;
if (player === 5) return playerWin;


if ((playerSelection.toLowerCase() === 'rock' && computerSelection.toLowerCase() === 'scissor') ||
(playerSelection.toLowerCase() === 'paper' && computerSelection.toLowerCase() === 'rock') ||
Expand All @@ -47,19 +40,25 @@ const btnRock = document.querySelector('#rock');
const btnPaper = document.querySelector('#paper');
const btnScissor = document.querySelector('#scissor');
const result = document.querySelector('#result');
const buttons = document.querySelector('#buttons');
const score = document.querySelector('#score')

btnRock.addEventListener('click', () => {
playerSelection = 'rock';
const computerSelection = getComputerChoice();
score.textContent = `PLAYER: ${player} VS MAC: ${mac}`
result.textContent = (playRound(playerSelection,computerSelection));
})
btnPaper.addEventListener('click', () => {
playerSelection = 'paper';
const computerSelection = getComputerChoice();
score.textContent = `PLAYER: ${player} VS MAC: ${mac}.`
result.textContent = (playRound(playerSelection,computerSelection));

})
btnScissor.addEventListener('click', () => {
playerSelection = 'scissor';
const computerSelection = getComputerChoice();
score.textContent = `PLAYER: ${player} VS MAC: ${mac}.`
result.textContent = (playRound(playerSelection,computerSelection));
})

0 comments on commit ef346b1

Please sign in to comment.