Rock, Paper, Scissors, Lizard, Spock in JavaScript

前端 未结 6 1783
感情败类
感情败类 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:11

    As several users have mentioned, your best bet for comparing is to convert the input to lowercase.

    For your second point, I would wrap the input parsing in a loop, like this:

    while(true){
        var input = getInput();
    
        if(isValid(input)){
            // check for the winner
            break;
        }else{
            // tell the user that their input is invalid
        }
    }
    

提交回复
热议问题