Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /* Program a single-player game of Rock, Paper, Scissors! You will need to code the following three functions:

1. Write a function, yourTurn(), which prompts the user to choose Rock, Paper, Scissors and returns their choice in lowercase. If they click cancel, return "nothing". This function will take in no input variables.

2. Write a function, computerTurn(), which randomly returns "rock", "paper", or "scissors". This function will take in no input variables.

3. Write a function, findResult(), which takes in the player choice and computer choice and returns "win", "lose", or "tie" based on the user's results.

The game will continue until either the player or the computer gets 3 wins. Use the alert() function to show the results of each round and printToScreen() to show who won the game.
*/

// Enter your code below this line

//1

 
 
const yourTurn = () => {
  let choice = prompt("Rock, Paper, or Scissors")
  let choose = ""
  if(choice == "cancel"){
    let choose = "nothing"
    return(choose)
  }
  if(choice == "Rock" || "Paper" || "Scissors"){
    choice = choice.toLowerCase();
    return(choice)
  }
}



const computerTurn = () => {
  let choice = Math.floor(Math.random() * 3) + 1;
  let choose = "";
  if(choice == 1){
    choose = "rock";
    return(choose)
  }
  if(choice == 2){
    choose = "paper";
    return(choose)
  }
  if(choice == 3){
    choose = "scissors";
    return(choose)
  }
}


let playerScore = 0;  
let computerScore = 0;   

const findresult = (player, bot) => {

let bots = bot;
  

  if(player == bot){
   alert("You chose " + player +  " and computer chose " + bot + ". Therefore you its a tie this round")
   
  }
  if(player == "rock"){
    if(bot == "paper"){
     alert("You chose " + player +  " and computer chose " + bot + ". Therefore you lose this round")
       computerScore += 1;
    }
    else if(bot == "scissors"){
     alert("You chose " + player +  " and computer chose " + bot + ".  Therefore you win this round")
       playerScore += 1;
    }
  }
  if(player == "paper"){
    if(bot == "scissors"){
      alert("You chose " + player +  " and computer chose " + bot + ". Therefore you lose this round")
      computerScore += 1;
    }
    else if(bot == "rock"){
      alert("You chose " + player +  " and computer chose " + bot + ".  Therefore you win this round")
      playerScore += 1;
    }
  }
  if(player == "scissors"){
    if(bot == "rock"){
      alert("You chose " + player +  " and computer chose " + bot + ". Therefore you lose this round")
      computerScore += 1;
    }
    else if(bot == "paper"){
      alert("You chose " + player +  " and computer chose " + bot + ".  Therefore you win this round")
      playerScore += 1;
    }
  }
}
//2



while(playerScore <= 2 && computerScore <= 2){
 let pTurn = yourTurn()
let cTurn = computerTurn()
findresult(pTurn,cTurn)
if(playerScore == 3){
  printToScreen("Congrats You win")
}
if(computerScore == 3){
  printToScreen("Try again next time")
}
}  
// DO NOT ALTER CODE WRITTEN BELOW THIS LINE
function printToScreen(text) {
  let r = Math.floor(Math.floor(Math.random() * 255 + 1));
  let g = Math.floor(Math.floor(Math.random() * 255 + 1));
  let b = Math.floor(Math.floor(Math.random() * 255 + 1));
  const svg = d3
    .select("body")
    .append("svg")
    .attr("width", 1500)
    .attr("height", 75);

  svg
    .append("text")
    .attr("y", 37.5)
    .attr("width", 450)
    .attr("height", 75)
    .attr("x", -1000)
    .attr("font-weight", "bold")
    .attr("font-size", "20px")
    .attr("fill", `rgb(${r},${g},${b}`)
    .attr("font-family", "Roboto")
    .text(text)
    .transition()
    .duration(1000)
    .attr("x", 37.5);
}

              
            
!
999px

Console