This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
let compscore=0;
let playerscore=0;
let winner='';
function computerPlay(){
const arr = ["rock","paper","scissors"];
const random = arr[Math.floor(Math.random()* arr.length)];
// console.log("computer:" arr[random]);
return random;
   }
function playerPlay(){
let option = prompt("choose an action");
return option;
   }
function playRound(ps,cs){
for(let i=0; i<=5;i ){
if (ps === cs){
return ('you draw!');
     }else if ((ps === 'rock') && (cs === 'scissors')){
playerscore ;
console.log( "score:" playerscore);
return("you win! rock beats scissors");
     } else if (ps === 'rock' && cs === 'paper'){
compscore ;
console.log("score:" compscore);
return("you lose! paper  beats rock");
     }else if(ps === 'paper' && cs === 'rock'){
playerscore ;
console.log("score:" playerscore);
return("you win! Paper beats scissors");
     }else if(ps === 'paper' && cs === 'scissors'){
compscore ;
console.log("score:" compscore);
return("you lose! scissors beats paper");
     }else if(ps === 'scissors' && cs === 'paper'){
playerscore ;
console.log("score:" playerscore);
return("you win! scissors beats paper");
     }else if(ps === 'scissors' && cs === 'rock'){
compscore ;
console.log("score:" compscore);
return("you lose! rock beats scissors");
     }
    }
    }
const ps=playerPlay();
const cs = computerPlay();
console.log("computer:" cs);
console.log(playRound(ps,cs));
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnjavasc...