Next Steps! Completely Stuck


#1

I don't know where to start with:

Next Steps
Congratulations on making your awesome game! But now comes the best bit. You have the skills to build a game of your own design! Below are some ideas:

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?


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

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


#2

You do not have to do anything to your code they are just suggesting ideas if you want to take this game further to redesign it or try something else with it. When you learn new stuff you can come back and try out different things to make the game better or just to have fun. That is one of the great things about coding!


#3

Brilliant, thank you for your assistance.


#4

No problem! Happy coding! :smiley:


#5

well, so far you haven't learned loops, which is ideal for repeat. You have learned functions, so maybe you can use functions to re-execute code? This is possible:

var example = function(choice1,choice2){
   if (choice1 === choice2) {
    console.log("The result is a tie!");
    return example(choice1,choice2);
  } else {
     console.log("rest of the code");
  }
}

you can also decide to wait, until you had loops before you take on the next steps. you could use the same strategy for invalid input:

var example = function(choice1){
    if (choice1 == "rock"){
      return true;
   } 
   /* two else if statements to check if choice1 is paper or scissors */
  else {
    return function(choice1);
  }
}

just some idea's.


#6

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