diff --git a/game.js b/game.js index 3d7e01b..67ae467 100644 --- a/game.js +++ b/game.js @@ -1,3 +1,107 @@ -// Write all your code here -// Replace the contents of this file with your own code -console.log('Hello, world!'); + + + + + + + + +let choices = ["rock", "paper", "scissors"]; + +function computerPlay(){ + return choices[Math.floor(Math.random()*3)] ; + +} + + + +let userScore=0; +const userScoreSpan=document.querySelector("#user-score-s"); +const computerScoreSpan=document.querySelector("#comp-score-s"); +const result =document.querySelector('#result') + +function winner(playerSelection, computerSelection) { + userScore ++; + userScoreSpan.textContent=userScore; + result.textContent= "You win! " + playerSelection +" beats " +computerSelection+"." ; + +} + +let computerScore=0; +function looser(playerSelection, computerSelection) { + + computerScore ++; + computerScoreSpan.textContent=computerScore; + result.setAttribute('font-size', '25px'); + result.textContent= "You Lose! " + playerSelection +" beats " +computerSelection+"." ; +} + + +function tie(playerSelection, computerSelection) { + + result.textContent= "Tie"; +} + + + + + + +function playRound(playerSelection){ + const computerSelection = computerPlay(); + switch (playerSelection+computerSelection){ + case "rockscissors": + case "paperrock": + case "scissorspaper": + winner(playerSelection, computerSelection); + break; + case "rockpaper": + case "paperscissors": + case "scissorsrock": + looser(playerSelection, computerSelection); + break; + case "rockrock": + case "paperpaper": + case "scissorsscissors": + tie(playerSelection, computerSelection); + break;} + } + + + const rock = document.querySelector('#rock'); + const paper = document.querySelector('#paper'); + const scissors = document.querySelector('#scissors'); + + +function game (){ + + rock.addEventListener('click', function(){ + playRound('rock') + }) + + + paper.addEventListener('click', function(){ + playRound('paper') + }) + + + scissors.addEventListener('click', function(){ + playRound('scissors') + }) + +} + + + +function fiveRound(){ + for (i=0; i<5; i++){ + let x =game(i); + return x + } +} + +fiveRound(); + + + + diff --git a/images/paper.jpeg b/images/paper.jpeg new file mode 100644 index 0000000..38edc52 Binary files /dev/null and b/images/paper.jpeg differ diff --git a/images/rock.jpeg b/images/rock.jpeg new file mode 100644 index 0000000..09c32dc Binary files /dev/null and b/images/rock.jpeg differ diff --git a/images/scissors.jpeg b/images/scissors.jpeg new file mode 100644 index 0000000..0303989 Binary files /dev/null and b/images/scissors.jpeg differ diff --git a/index.html b/index.html index 947177f..b29e9fd 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,28 @@ Rock, Paper, Scissors! + + + +
+ + + +
+ +
+

Choose one of the above to make your turn!

+ +

+ + +
+ +

Your Score:

0 +

Computer Score:

0 +
+ diff --git a/style.css b/style.css new file mode 100644 index 0000000..98ad9b0 --- /dev/null +++ b/style.css @@ -0,0 +1,33 @@ + + + + + +div{ + + margin-top:80px; + text-align: center; + +} + +h1 { + + text-align: center; + + + +} + + + +img { + padding:20px; +} + + + +img:hover{ + height: 80%; + cursor: pointer + +} \ No newline at end of file