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.
edit: now returning undefined
function computerPlay(){
const arr = ["Rock","Paper","Scissors"];
const random = Math.floor(Math.random()* arr.length);
return arr[random];
}
function playerPlay(){
let option = prompt("choose an action");
return option;
}
function playRound(ps,cs){
if (ps === cs){
return ('you draw!');
}else if ((ps === 'rock') && (cs === 'scissors')){
return("you win! rock beats scissors");
} else if (ps === 'rock' && cs === 'paper'){
return("you lose! paper  beats rock");
}else if(ps === 'paper' && cs === 'rock'){
return("you win! Paper beats scissors");
}else if(ps === 'paper' && cs === 'scissors'){
return("you lose! scissors beats paper");
}else if(ps === 'scissors' && cs === 'paper'){
return("you win! scissors beats paper");
}else if(ps === 'scissors' && cs === 'rock'){
return("you lose! rock beats scissors");
}
}
const ps=playerPlay();
const cs = computerPlay();
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...