Const ReadLine = require ("Readline-sync");//output FunctionConsole.log ("Welcome into the scissors game"); Console.log ("Please choose the punch: 1. Stone 2. Scissors 3. Cloth "); let option= Readline.question ()-0; while(IsNaN (option) | | Option < 1 | | option > 3) {Console.log ("Please re-lose:"); Option= Readline.question ()-0;}//the computer randomly punchesLet random = parseint (Math.random () * 3 + 1);if(Random = = 1) {Console.log ("Computer Punch: Stone");}Else if(Random = = 2) {Console.log ("Computer Punch: Scissors");}Else{Console.log ("Computer Punch for: cloth");}//the player punchesif(option = 1) {Console.log ("Player Punch: Stone");}Else if(option = 2) {Console.log ("Player Punch: Scissors");}Else{Console.log ("Player punch: Cloth");}//Judgingfunctionname (A, b) {if(A-b = = 1 | | A-b = 2) {Console.log ("Computer Victory"); }Else if(A-b = = 0) {Console.log (Draw); }Else{Console.log ("Player wins"); }}name (random, option)
JavaScript for human-machine scissors