This forum is now read-only. Please use our new forums! Go to forums
It says i need to capitalize the M in (Math) but it already is!! Help!
var userChoice=prompt(“Rock, Paper, or Scissors?”) var computerChoice = Math.random() if (computerChoice < 0.34) { computerChoice = “rock”; } else if(computerChoice <= 0.67) { computerChoice = “paper”; } else { computerChoice = “scissors”; } console.log(“Computer: “ + computerChoice);
var compare = function (choice1,choice2){ if (choice1 === choice2) { return “The result is a tie!” ;} else if ( choice1 === “rock” ){ if ( choice2 === “scissors” ){ return “rock wins”; } else { return “paper wins” ;}} else if ( choice1 === “paper” ){ if ( choice2 === “rock” ){ return “paper wins” ; } else { return “scissors wins” ; }} }; compare(userChoice,computerChoice);
Answer 553b00b895e378fc5800036b
under certain circumstances you can shoot your Browser in an inconsistent state.
Therefor it is of an advantage to know that you have 2 reset facilities:
One is the use of the F5-key which does a refresh Browser
and
Two, select© your code Then use the Reset Code button of the course-window, then paste your code back in.
Addendum from Tony de araujo General Notes: Always refresh the browser after making corrections: CTRL f5 ( if on Windows or Linux) CMD r ( if on a MAC).
Answer 553b0138d3292f3136000188
================================
Now you want to execute the compare function, as the compare function expects 2 parameters you have to provide it 2 arguments which in our case would be userChoice and computerChoice. compare(userChoice,computerChoice);
some quotes from the outer-world:
argument is the value/variable/reference being passed in, parameter is the receiving variable used within the function/block
OR
“parameters” are called “formal parameters”, while “arguments” are called “actual parameters”.
================================
As you are using the return-_statement in your compare function you will only get a return-value no-display. You can however capture this return-value in a variable and then use the console.log()-method to do a display.
var theResult = compare(userChoice,computerChoice);
console.log( theResult );
OR directly
console.log( compare(userChoice,computerChoice) );
P.S. I would put an extra console.log( userChoice ); just under the computerChoice-display
Answer 553b015ae39efe19f10003cf
+++++++++++++++ truth table +++++++++ Maybe if you create a truth-table it is easier to understand. You will look out of perspective og choice1:
| ch-2 | ch-2 | ch-2
| rock | paper | scissors
----------------|-------|--------|----------
| | paper | rock
choice1 rock | X | wins | wins (first else if )
| | |
----------------|-------|--------|----------
| paper | |scissors
choice1 paper | wins | X | wins (second else if )
| | |
-----------------|-------|--------|----------
| rock |scissors|
choice1 scissors | wins | wins | X (third else if )
| | |
-----------------|-------|--------|----------
We have to evaluate 9 possibilities: In written form:
if choice1 equals choice2 then "A tie" (all the X'ses)
else if choice1 is "rock"? Given choice1 is "rock",
a. if choice2 === "scissors", then "rock" wins.
b. if choice2 === "paper", then "paper" wins.
else if choice1 is "paper"? Given choice1 is "paper",
a. if choice2 === "rock", then "paper" wins.
b. if choice2 === "scissors", then "scissors" wins.
else if choice1 is "scissors"? Given choice1 is "scissors",
a. if choice2 === "rock", then "rock" wins.
b. if choice2 === "paper", then "scissors" wins.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
Very Nicely done sir