Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting labs 1,2,3 #168

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding my Java-Redo lab
renanharrigan committed Apr 29, 2022
commit ca7a2aa8188efaf5a1eb25e37357d68e6509cb31
70 changes: 70 additions & 0 deletions Code/renan/java/RPS/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const computerChoiceDisplay = document.getElementById('computer-choice')
const playerChoiceDisplay = document.getElementById('player-choice')
const resultDisplay = document.getElementById('result')
const choices = document.querySelectorAll('button')
let playerChoice
let computerChoice
let result

// console.log(computerChoiceDisplay)
// console.log(computerChoiceDisplay.id)
//console.log(choices)



console.log(playerChoiceDisplay.innerHTML, 'before')
//listeners
choices.forEach(choice=>choice.addEventListener('click', (e)=>{
playerChoice = e.target.id
playerChoiceDisplay.innerHTML = playerChoice

createComputerChoice()
getResult()
//console.log(playerChoiceDisplay, 'after')
}))

function createComputerChoice(){
const randomNumber = Math.floor(Math.random() *choices.length) +1 //3 +1
console.log(randomNumber)

if(randomNumber === 1){
computerChoice = 'rock'
}
if(randomNumber=== 2){
computerChoice = 'scissors'
}
if(randomNumber=== 3){
computerChoice = 'paper'
}

computerChoiceDisplay.innerHTML = computerChoice

}
function getResult(){

if(computerChoice===playerChoice){
result = 'We have a tie!'
}
if(computerChoice=== 'rock' && playerChoice ==='paper'){
result = 'You won the game'
}
if(computerChoice=== 'rock' && playerChoice ==='scissors'){
result = 'You lost the game'
}
if(computerChoice=== 'paper' && playerChoice ==='scissors'){
result = 'You won the game'
}
if(computerChoice=== 'paper' && playerChoice ==='rock'){
result = 'You lost the game'
}
if(computerChoice=== 'scissors' && playerChoice ==='rock'){
result = 'You won the game'
}
if(computerChoice=== 'scissors' && playerChoice ==='paper'){
result = 'You lost the game'
}

resultDisplay.innerHTML = result
}

createComputerChoice()
22 changes: 22 additions & 0 deletions Code/renan/java/RPS/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RPS</title>
<script defer src="app.js"></script>

</head>
<body>
<h2>Computer Choice: <span id="computer-choice"></span></h2>
<h2>Player Choice: <span id="player-choice"></span></h2>
<h2>Result: <span id="result"></span></h2>


<button id="rock">Rock</button>
<button id="paper">Paper</button>
<button id="scissors">Scissors</button>

</body>
</html>