Skip to content

Commit

Permalink
define playGame, refine code overall
Browse files Browse the repository at this point in the history
  • Loading branch information
rishikpogu committed May 28, 2024
1 parent f3b7fc3 commit de2177b
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,60 @@ function getComputerChoice() {
return y
}

let cc = getComputerChoice()
let cc

function getHumanChoice() {
return prompt("What do you chose to defeat me?")
}

let hc = getHumanChoice().toLowerCase()

console.log(`my choice ${cc}`)
console.log(`your choice ${hc}`)
let hc

let humanScore = 0
let computerScore = 0

function playRound(cc, hc) {
if (cc === hc) {
y = "It's a tie, bruh"
function playGame() {
function playRound(cc, hc) {
cc = getComputerChoice()
hc = getHumanChoice().toLowerCase()

if (cc === hc) {
y = "It's a tie, bruh"
}
else if (cc === "rock" && hc === "paper" || cc === "paper" && hc === "scissors" || cc === "scissors" && hc === "rock") {
y = `Ughh, You've won. Take a point. (${hc} beats ${cc})`
humanScore++
}
else if (cc === "rock" && hc === "scissors" || cc ==="paper" && hc === "rock" || cc === "scissors" && hc === "paper") {
y = `Yayy, I win! (${cc} beats ${hc})`
computerScore++
}
else {
y = "I might've fucked up my code again"
}
console.log(`my choice ${cc}`)
console.log(`your choice ${hc}`)
console.log(y)
console.log(`my score ${computerScore}`)
console.log(`your score ${humanScore}`)
}

for (let z=1; z<6; z++) {
console.log(`Round ${z}`)
playRound(cc, hc)
}
else if (cc === "rock" && hc === "paper" || cc === "paper" && hc === "scissors" || cc === "scissors" && hc === "rock") {
y = `Ughh, You've won. Take a point. (${hc} beats ${cc})`
humanScore++

if (humanScore === computerScore) {
console.log("C'mon, a tie finally, bruhhh.")
}
else if (cc === "rock" && hc === "scissors" || cc ==="paper" && hc === "rock" || cc === "scissors" && hc === "paper") {
y = `Yayy, I win! (${cc} beats ${hc})`
computerScore++
else if (humanScore > computerScore) {
console.log(`Congo, You win by ${humanScore - computerScore} pts. I'll comeback stronger!!!`)
}
else if (humanScore < computerScore) {
console.log(`Yayy! I win by ${computerScore - humanScore} pts. Comeback stronger soldier. Respect++`)
}
else {
y = "I might've fucked up my code again"
console.log("I'm sure I'm not that worse to fk up my code thrice")
}
return y
}

let result = playRound(cc, hc)

console.log(result)
console.log(`my score ${computerScore}`)
console.log(`your score ${humanScore}`)
playGame()

0 comments on commit de2177b

Please sign in to comment.