|
|
|
|
|
const readline = require("readline").createInterface({ |
|
input: process.stdin, |
|
output: process.stdout, |
|
}); |
|
|
|
const arr = ["rock", "paper", "sicssor"]; |
|
const ai = arr[Math.floor(Math.random() * arr.length)]; |
|
|
|
readline.question( |
|
"rock, paper, sicssor, which one you choose? ", |
|
(yourChoice) => { |
|
if (yourChoice === "rock") { |
|
if (ai === "paper") { |
|
console.log("You lose"); |
|
} else if (ai === "sicssor") { |
|
console.log("You win"); |
|
} else { |
|
console.log("It's tie"); |
|
} |
|
} else if (yourChoice === "paper") { |
|
if (ai === "paper") { |
|
console.log("It's tie"); |
|
} else if (ai === "sicssor") { |
|
console.log("You lose"); |
|
} else { |
|
console.log("You win"); |
|
} |
|
} else if (yourChoice === "sicssor") { |
|
if (ai === "paper") { |
|
console.log("You win"); |
|
} else if (ai === "sicssor") { |
|
console.log("It's tie"); |
|
} else { |
|
console.log("You lose"); |
|
} |
|
} |
|
readline.close(); |
|
} |
|
); |
|
|