4/9 What am I doing wrong


#1

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();

if(computerChoice < 0.34) {
return computerChoice = "rock";
}
else if(computerchoice < 0.67) {
return computerChoice = "paper";
}
else {
return computerChoice = "scissors";
}
console.log(computerChoice);


#2

Instead of just this try using,

<=


#3

And remove your return statements.


#4

Ye I fixed it but i didn't had to use <= 0.33 because it is the same as < 0.34


#5

Have you changed the return part


#6

yes sir! :smiley: :smiley: :smiley: :smiley: (I have to put atleast 20 letters in it)


#7

Can I see your code now :slight_smile:


#8

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


#9

Can you help me at 8/9:

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


#10

Try indenting like this, and also see how I've used <= instead of <

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice <= 0.33) {
    computerChoice = "rock";
}
else if (computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}
console.log(computerChoice)

#11

I know but it is basically the same


#12

There should only be three brackets at the end, and you never called your compare function

else {
        return "rock wins";
    }
}
};
compare(userChoice, computerChoice)

#13

Nevermind i fixed it. I only had to call the compare function but i didn't had to remove a bracket


#14

var userChoice = prompt("Do you choose rock, paper or scissors?")
var computerChoice = Math.random();
console.log(computerChoice);
if(computerChoice <= 0.33) {
computerChoice= "rock";
}
else if(computerchoice <= 0.67) {
computerChoice= "paper";
}
else {
computerChoice= "scissors";
}
console.log(computerChoice);


#15

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