Hi, I am new to Javascript. I have been trying to do a rock , paper and scissors problem where I need to keep track of the score after playing 5 rounds with the computer (and announce the winner). I honestly need help with the scoring part (I tried a lot of things but am not able to see the issue), and forgive me if the code is not efficient, I have been trying to use what I have learned thus far and have not had any luck with the last part. I am thankful in advance for any help I can get with this problem.
<script>
function computerPlay() {
let x=Math.floor(Math.random() *3);
switch(x){
case 0:
return "Rock";
break;
case 1:
return "Paper";
break;
case 2:
return "Scissors";
}
}
function playRound(playerselection, computerselection){
if (playerselection.toLowerCase()===computerselection.toLowerCase()){
return "It is a tie";
}
else if (playerselection.toLowerCase()==="rock" && computerselection.toLowerCase()==="paper"){
return "you lose, paper defeats rock";
}
else if (playerselection.toLowerCase()==="paper" && computerselection.toLowerCase()==="scissors") {
return "you lose, scissors defeat paper";
}
else if (playerselection.toLowerCase()==="scissors" && computerselection.toLowerCase()==="rock"){
return "you lose, rock defeats scissors"
}
else if (playerselection.toLowerCase()==="rock" && computerselection.toLowerCase()==="scissors"){
return "you win, rock defeats scissors";
}
else if (playerselection.toLowerCase()==="paper" && computerselection.toLowerCase()==="rock") {
return "you win, paper defeats rock";
}
else if (playerselection.toLowerCase()==="scissors" && computerselection.toLowerCase()==="paper"){
return "you win, scissors defeat paper"
}
}
let myPoints=0;
let comPoints=0;
function game() {
let i=0;
for (;i<5;i++) {
let x=prompt("choose your weapon: ");
y=playRound(x,computerPlay());
console.log(y);
if (y.slice(0,7).toLowerCase==="you win"){
myPoints+=1;
}
else if (y.slice(0,8).toLowerCase==="you lose") {
comPoints+=1;
}
}
alert(myPoints);
}
let a="you win, rock beats scissors"
a=a.slice(0,7).toUpperCase();
if (a==="YOU WIN"){
console.log(a);
}
</script>