9. Next Steps


#1

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

No matter how many times i try, the computerChoice never gets paper. What needs to be changed?


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

var compare = function(userChoice, computerChoice){
    
    if (userChoice === computerChoice) {
        return("The result is a tie!")}
    
    else if (userChoice === "rock") {
        if (computerChoice === "scissors") {
            return ("rock wins")}
        else {
            return ("paper wins")} }
    
    else if (userChoice === "paper") {
        if (computerChoice === "rock") {
            return ("paper wins")}
        else {
            return ("scissors wins")} }
    
    else if (userChoice === "scissors"){
        if (computerChoice === "rock"){
            return ("rock wins")}
        else {
            return ("scissors wins")} }
}
console.log("User: " + userChoice);
console.log(compare(userChoice, computerChoice));


#2

Have you considered what actions the code should be carrying out in order to reach paper?

Can you add prints that check if those things are happening?

For example, if you run just this part:

var computerChoice = Math.random();
if (computerChoice < 0.33) {
	computerChoice = "rock";
} else if( computerChoice <= 0.66) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";} 
console.log("Computer: " + computerChoice);

output:

Computer: paper

Seems like the problem is with your observation that computer never gets paper. It does.


#3

Yeah, seems like I just had bad luck with the:

var computerChoice = math.random();

Thanks for the help anyway :slight_smile:


#4

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