This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by amber_hernandez
almost 9 years

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

0 votes

Permalink

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&copy 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).

points
Submitted by Leon
almost 9 years

Answer 553b0138d3292f3136000188

0 votes

Permalink

================================

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

points
Submitted by Leon
almost 9 years

Answer 553b015ae39efe19f10003cf

0 votes

Permalink

+++++++++++++++ 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.
points
Submitted by Leon
almost 9 years

1 comments

CodeNameMolina almost 9 years

Very Nicely done sir