Rock, Paper, Scissors in JavaScript

前端 未结 13 1715
野的像风
野的像风 2020-12-03 00:13

I\'m working on making my first game (Rock Paper Sissors) and I ran into an issue where when the userChoice is scissors and the com

13条回答
  •  盖世英雄少女心
    2020-12-03 00:43

    This is the code I made at this exercise and it worked like a charm... I used logical operators on my "if" statements, and it was accepted(obviously).

    Give it a try :D

    var userChoice = prompt("Do you choose rock, paper or scissor?");
    var computerChoice = Math.random();
    if (computerChoice > 0 && computerChoice < 0.33) {
      computerChoice = "Rock";
    } else if (computerChoice > 0.34 && computerChoice < 0.67) {
      computerChoice = "Paper";
    } else {
      computerChoice = "Scissor";
    }
    console.log(computerChoice);

提交回复
热议问题