Need to print what is in "if" statements..doesnt work though!


#1

var userChoice = prompt("Do you choose 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);
console.log("User: " + userChoice);
var compare = function(userChoice, computerChoice)
{    
    if(userChoice === computerChoice)
       {return "The result is a tie!";}
    if(userChoice === "paper" && computerChoice === "rock")
        {return "paper wins";}
    if(userChoice === "paper" && computerChoice === "paper") 
        {return "scissors win";}  
    if(userChoice ===  "scissors" && computerChoice === "rock")
        {return "rock wins";}
    if(userChoice ===  "scissors" && computerChoice === "paper")
        {return "scissors wins";}
};
compare(userChoice, computerChoice);

#2

Have a read through
= http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate

  • on the build of the IF ELSE-IF statement structure.
  • on the truth-table to look at who wins when. paper&&paper =>scissors wins ???

#3

Also, just a hint, formatting is very important regarding programming....
Use LOTS of tabs, it'll help a lot :smile:


#4

Good point but here it also was a "problem" with the forum as code that is posted as plain text loses some of its formatting. So when code is posted please use the </> button or use backticks like this:

//inline code: text text `code` text text
or for longer sections

```
here goes your code
```

the version with the 3 backticks also allows syntax highlighting as you can see in the question.