I am trying to make a rock, paper scissor console game with JS but only first testing the waters with rock and scissor. I have a function that takes in a randomly generated value from an array and then asks the user for their input and them compares the two values. the "win" variable determines if a winner is declared or not with help of check_winner() function. But my boolean value for win always remains false.
Here's the code:
var arr = ['rock', 'scissor']
let win = false
function play(arr){
var b = arr[(Math.floor(Math.random()*2))]
console.log(b)
var a = prompt('Enter choice:')
console.log(a)
do{
if(a==="rock" && b==="scissor"){
console.log("Rock crushes Scissor! You win bitch!")
win=true
}
else if(b==="rock" && a==="scissor"){
console.log("Rock crushes Scissor! You lose bitch!")
win=true
}
}
while(win=false);
check_winner(win)
}
function check_winner(win){
if(win===true){
console.log("gamne over")
}
else{
prompt("Enter again")
}
}
play(arr)
Aucun commentaire:
Enregistrer un commentaire