Next Steps


#1


At the end of this course, it tells you this:

What if a user makes an inappropriate choice like 'dog'? How can we extend the function to handle that?

What if players in the game could also choose Rope in this game?

In this version, if both players make the same choice, the game returns a tie. What if the game didn't end there but instead asked both players for new choices?

Just so I can grasp on JAVA and teach myself a thing or two in order for me to brainstorm when I want to do my own project. How would approach this? What if did want to add more to this rock, paper, scissor game. How do I go about?
I appreciate the help.

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



#2

Generally just consider what actions need to be carried out. Imagine you're the computer, what would you need to do? Writing code is to describe that. You can start by writing down what those actions are in English, focus on what's to happen, getting those actions to line up correctly. Then expand on things that are too abstract until everything is detailed enough that you can write that as code, you might then make your text comments and fill in the code between those descriptions.


#3

Makes sense. I guess it's only a matter of how much time I invest into learning Java and programming and how to make sense of it all. I hope it clicks. I'm really determined to dive deep into this stuff.


#4

@steveblurr start small, don't overthink these steps.

Step 1: Try to display a message in the console if the user selects an inappropriate choice. (hint: "else" statement within your function).

Step 2: This will require adding an additional choice to computerChoice and will require you to add multiple "else if" blocks within your function.

Step 3: Now it's important to think of what you are trying to do here, you are trying to display the prompt box again so that they can re-enter new choices. since userChoice and computer choice are already declared you only need to change your code to this:

if (choice1 === choice2){
        userChoice = prompt(" Tie! Please choose another user value:");
        computerChoice = prompt("Tie! Please choose another computer value:");
    }

After you have done that, you need to think about scope and to accommodate for that, call your compare function within your function (see full code below [missing step 2]):

// Comparing computer choice to user choice
var compare = function(choice1, choice2){
    if (choice1 === choice2){
        userChoice = prompt(" Tie! Please choose another user value:");
        computerChoice = prompt("Tie! Please choose another computer value:");
    }
    
    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 === "rock"){
            return "rock wins";
        }
        else{
            return "scissors wins";
        }
    }
    
    else{
       userChoice = prompt("You have entered an incorrect selection. Try again:");
    }
    
    console.log(compare(userChoice, computerChoice));
}

console.log(compare(userChoice, computerChoice));

You'll notice that the code works but you get undefined printed out each time you prompt again. This is because we're calling the function twice in 2 different scopes and only 1 gets used.

I need to figure out how to use just one scope for them all.

Hope I have helped in some way.


#5

All the insights help out. I'm just trying to understand the big picture. I'm not familiar with the concepts and it's hard for me to stop for a minute and try to understand what I'm trying to do. I keep catching myself coming the forums to seek answers and I feel like I'm not picking my brain enough to think outside the box. Thanks for this.


#6

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