// Not sure if i made a rookie mistake or something else, but i have had a lot of trouble trying to find out what the problem is. It says SyntaxError: Unexpected token )
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === 'rock'|| userInput === 'paper' || userInput === 'scissors') {
return userInput;
}
else {
console.log('Input is invalid. try again.');
}
}
function getComputerChoice() {
switch (Math.floor(Math.random() * 3)) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
}
function determineWinner(userChoice,computerChoice) {
if(userChoice === computerChoice) {
return 'The game is a tie!';
}
if(userChoice === 'rock') {
if(computerChoice === 'paper') {
return 'The computer wins!';
}
else {
return 'You win!';
}
}
if(userChoice === 'paper') {
if(computerChoice === 'scissors') {
return 'The computer wins!';
}
else {
return 'You win!';
}
}
if(userChoice === 'scissors') {
if(computerChoice === 'rock') {
return 'The computer wins!';
}
else {
return 'You win!';
}
}
Thank you a whole bunch, but… Now userChoice is undefined, which at first seemed logical since i hadden’t put it in yet. but now that i did, it is still undefined.
'Til now I’ve been responding on intuition. Beyond this I need context, meaning a link to the exercise so we can play things out. Please reply with same. Thank you.
Your error message looks like it’s missing parts, here’s what I get locally:
/tmp/derp/aeotnuh/aoeu.js:52
});
^
SyntaxError: Unexpected token )
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:670:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
at startup (internal/bootstrap/node.js:240:19)
The “at …” lines aren’t saying anything relevant in this case. But this says it’s line 52 which isn’t even in the code. NodeJS puts your code in a function and this line 52 is where it ends.
What makes the parenthesis unexpected is that something else is still “open”, something like this:
([[
Two ]'s need to be added before ), making ) unexpected at this point
I’d (temporarily) delete roughly half your code and run it again to determine which half the problem is in, repeat until narrowed down sufficiently to be spotted. You’d generally avoid this problem by always inserting and removing various brackets in pairs
(Except I spot the missing bracket immediately because of its effect on indentation)
JS doesn’t clearly distinguish between something not being defined, and the value undefined
For example, the result of this function is undefined, so the result is as a matter of fact defined…
() => {}
So if something’s undefined start looking at where it was supposed to come from.
Again, like with trying to find a missing bracket, starting somewhere in the middle of events to see if the desired value is there, is a good idea because that will quickly narrow down where it got lost