Reference Error: determineWinner is not defined/ where to place secret code?


#1

function getUserChoice() {
var userInput = prompt('What is your name?');
userInput = userInput.toLowerCase();

if(userInput === 'rock'|| userInput === 'paper' || userInput === 'scissors') {
return userInput;
} else {
console.log('Error!');
}
}

function getComputerChoice() {
var randomNumber = Math.floor(Math.random() * 3);

switch(randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
}

function detertmineWinner() {
if(userChoice === computerChoice) {
return 'The game is a tie!';
}

if(userChoice === 'rock') {
if(computerChoice === 'paper') {
return 'The computer won!';
} else {
return 'You won!';
}
}

if(userChoice === 'paper') {
if(computerChoice === 'rock') {
return 'The computer won!';
} else {
return 'You won!';
}
}

if(userChoice === 'bomb') {
return 'You have outsmarted us. Congrats';
}
}

function playGame() {
var userChoice = getUserChoice;
var computerChoice = getComputerChoice;

console.log(userChoice);
console.log(computerChoice);
console.log(determineWinner (userChoice , computerChoice));
}
playGame();


#2

var userChoice = getUserChoice;
var computerChoice = getComputerChoice;

Try giving the functions parenthesis:

var myThing = myFunction();

Reply if you need more help :slight_smile:


#3

That did not work plus I don't believe I need to add parameters/parenthesis to my variables. It still gives the error that determineWinner is not defined. Am I missing a curly bracket or is it in the wrong place? Please help anyone.

Thanks


#4

I think this specific error is caused by a simple typo on this line:

function detertmineWinner() {

detertmine should be determine


#5

I would "like" your post if I could, but I reached the max amount of "likes". :slight_smile:


#6

OMG, thanks a million. Also where would I place the if statement referring to the secret code


#7

function getUserChoice() {
	var userInput = prompt('What is your name?');
	userInput = userInput.toLowerCase();

	if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
		return userInput;
	} else {
		console.log('Error!');
	}
}

function getComputerChoice() {
	var randomNumber = Math.round(Math.random() * 3);
	var a;
	switch (randomNumber) {
		case 0:
			a = 'rock';
			break;
		case 1:
			a = 'paper';
			break;
		case 2:
			a = 'scissors';
			break;
	}
	return a;
}

function determineWinner() {
	if (userChoice === computerChoice) {
		return 'The game is a tie!';
	} else if (userChoice === 'rock') {
		if (computerChoice === 'paper') {
			return 'The computer won!';
		} else {
			return 'You won!';
		}
	}

	if (userChoice === 'paper') {
		if (computerChoice === 'rock') {
			return 'The computer won!';
		} else {
			return 'You won!';
		}
	}

	if (userChoice === 'bomb') {
		return 'You have outsmarted us. Congrats';
	}
}

function playGame() {
	var userChoice = getUserChoice();
	var computerChoice = getComputerChoice();

	console.log(userChoice);
	console.log(computerChoice);
	console.log(determineWinner(userChoice, computerChoice));
}
playGame();

Take a look at the difference between my code that works (above) and the code that doesn't :no_mouth:


#8

I have found my error with reference not found. Now I am trying to figure out where to place the secret code.
Thanks


#9

What is the secret code?


#10

The instructions state: Make this game better by adding a secret cheat code. If a user types in 'bomb' as their choice, then make sure they win, no matter what.

So I wrote the following code:

 if(userChoice === 'bomb') {
    if(computerChoice === 'rock' || computerChoice === 'scissors' || computerChoice === 'paper');
    return 'You have outsmarted the computer. Congrats';
  }

I placed it inside the determineWinner function, however, every time I type bomb in the prompt it returns error.


#11

Yes, you put your secret code in the right place. You just need to add to your:

	if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
		return userInput;
	}

And check if userInput === 'bomb'. Hope this helps!