I am currently trying to make rock, paper, scissors in the browser using only JS. I am using prompt and alert to tell the values but my program is not working after putting a while. Before the while loops, the alert function is working but after using while loop, nothing is happening. I don't know why. Here's my code->
const getRandom = (arr) => {
return arr[Math.floor(Math.random() * arr.length)];
};
alert ("Welcome to stone,paper and scissors. you will play against the computer.You will have ten chances to prove your worth")
let chances = 0
const arr = ["stone", "paper", "scissors"]
let uwins = 1
let cwins = 1
while (chances <= 9) {
let inp = prompt("Please enter the value")
let rand = (getRandom(arr));
if (inp == 'stone' && rand == 'scissor') {
alert("you won")
chances += 1
alert(`You have ${chances} chances left`)
console.log(rand)
++uwins
}
else if (inp == 'stone' && rand == 'paper') {
alert("you lost")
chances += 1
alert(`You have ${chances} chances left`)
console.log(rand)
cwins += 1
}
else if (inp =='stone' && rand =='stone'){
alert("its a tie!!")
chances += 1
alert(`You have ${chances} chances left`)
console.log(rand)
}
// ``````````````````````````````````````````````````````
if (inp == 'paper' && rand == 'scissor') {
alert("you lost")
chances += 1
alert(`You have ${chances} chances left`)
console.log(rand)
cwins += 1
}
else if (inp == 'paper' && rand == 'paper') {
alert("it a tire!!")
chances += 1
alert(`You have ${chances} chances left`)
console.log(rand)
}
else if (inp =='paper' && rand =='stone'){
alert(" you won")
chances += 1
alert(`You have ${chances} chances left`)
console.log(rand)
++uwins
}
// ``````````````````````````````````````````````````````
if (inp == 'scissor' && rand == 'scissor') {
alert("it a tie!!")
chances += 1
alert(`You have ${chances} chances left`)
console.log(rand)
}
Please help