Rock, Paper, Scissors, Lizard, Spock in JavaScript

前端 未结 6 1778
感情败类
感情败类 2020-11-28 15:36

I\'m kind of new to JavaScript. I just started learning it, and I decided to make a \'Rock, Paper, Scissors, Lizard, Spock\' game. Here is the code:

var use         


        
6条回答
  •  清歌不尽
    2020-11-28 16:13

    I would write a function to get the correct response instead of doing it all inline.. that's just me..

    function getUserChoice(){
        var invalidPin = true;
        var response;
        while(invalidPin){
            response = prompt("choose your thing..");
                if(response == "rock" || response == "paper" || response == "scizerz"){
                    invalidPin = false;
                }
            }
        }
        return response;
    }
    

    then you can get the user's choice simply by calling the function

    var userChoice = getUserChoice();
    

提交回复
热议问题