It works! But should it have?


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661


Ok, wow.

It worked, but I inadvertently hit save and submit and it worked but without "comparing" etc. SOooo what's up?


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);

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 if (choice1 === "paper"){
        if (choice2 === "rock"){
            return "paper wins"
        }else if (choice1 === "scissors"){
            if (choice2 === "rock"){
                return "rock wins"
            }else{
                return "scissors wins"
            }
        }
    }
  }
 };


#2

You don't have to be a genius to know that your code is incorrect. Just add the call to the compare function as it's stated in the instructions and test it.

The goal of codecademy is to help you learn, but you have to want to learn. So if you know that your code is faulty... fix it. The successful result of SCT is only a hint that probably your code is correct. But it's up to you to make sure.

Codecademy is not able to predict every stupidity in our codes :slight_smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.