diff --git a/game.js b/game.js index 3d7e01b..ba278fb 100644 --- a/game.js +++ b/game.js @@ -1,3 +1,54 @@ -// Write all your code here -// Replace the contents of this file with your own code -console.log('Hello, world!'); + +const options = ['rock', 'paper', 'scissors']; + +document.getElementById('rock').addEventListener('click', function(e){ + let round = playRound('rock', computerPlay()); +}); +document.getElementById('paper').addEventListener('click', function(e){ + let round = playRound('paper', computerPlay()); +}); +document.getElementById('scissors').addEventListener('click', function(e){ + let round = playRound('scissors', computerPlay()); +}); + +//computer's choice +function computerPlay() { + return options[Math.floor(Math.random() * options.length)]; +} + +function addPointsToUser(){ + points += 1; + document.getElementById("userScore")[0].innerHTML = points; +} + +function addPointsToComp(){ + points += 1; + document.getElementById("pcScore")[1].innerHTML = points; +} + + +function playRound(playerSelection, computerSelection) { + +if (playerSelection === computerSelection) { + document.getElementById("p").innerHTML = "You made the same choice! Try Again"; + + } else if((playerSelection === 'paper' && computerSelection === 'rock') || + (playerSelection === 'rock' && computerSelection === 'scissors') || + (playerSelection === 'scissors' && computerSelection === 'paper')) { + document.getElementById("p").innerHTML = "You win! You chose:" + playerSelection; + addPointsToUser(); + } + else{ document.getElementById("p").innerHTML = "Computer win!"; + addPointsToComp(); + } +} + + /* function game() { + let rounds= 0; +while (rounds < 5) { +const result = playRound(playerSelection, computerPlay()); +const whoisthewinner = prompt(result); +rounds++; + } +} +game(); */ diff --git a/images/paper.png b/images/paper.png new file mode 100644 index 0000000..1fad4bf Binary files /dev/null and b/images/paper.png differ diff --git a/images/rock.png b/images/rock.png new file mode 100644 index 0000000..87e9285 Binary files /dev/null and b/images/rock.png differ diff --git a/images/scissors.png b/images/scissors.png new file mode 100644 index 0000000..18db5eb Binary files /dev/null and b/images/scissors.png differ diff --git a/index.html b/index.html index 947177f..00a139b 100644 --- a/index.html +++ b/index.html @@ -3,8 +3,49 @@
MAKE YOUR MOVE!
+ +
+
+
+