Hello StackOverflow Community,
I have been studying JavaScript for about 3 days give or take and I have created a rock paper scissor “game” that runs but only with the player decision is added to the code. I wanted to fix this instead so that an prompt alert pops up to ask “Pick Rock, Paper, Scissor Now” and have the game use that input as the deciding factor to who will win. I have ran the code that I have provided and ended up this error:
a internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'readline-sync'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/tmp/zUokdwLcHz.js:1:20)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
I tried reviewing my spelling and ()/;/, to make sure that they are all correct and I feel like they are. I am sure this is an easy fix so thank you in advance you if you can guide me the correct way.
Here is the code:
const userInput = prompt("What will you shoot")
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput;
} else {
console.log("Error!");
}
const ComputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3)
if (randomNumber === 0) {
return "rock";
} else if (randomNumber === 1) {
return "paper";
} else {
return "scissors";
}
}
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return "Tie, please try again";
} else if (userChoice === "paper" && computerChoice === "rock") {
return "Player wins";
} else if (userChoice === "scissors" && computerChoice === "Paper") {
return "Player wins";
} else if (userChoice === "rock" && computerChoice === "scissors") {
return "Player wins";
} else if (userChoice === "bomb") {
return "Player wins"
} else {
return "Computer Wins"
}
}
const playGame = () => {
const userChoice = getUserChoice('')
const computerChoice = ComputerChoice()
console.log("you threw a " + userChoice);
console.log("The computer threw a " + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}
playGame();