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


#1

if(userChoice!=="rock"||userChoice!=="paper"||userChoice!=="scissors"){
console.log("YOU ENTERED WRONG CHOICE!");
exit(0);
}

will this help ??????


#2

@neo_play,

You must not change the functionality of the compare function
as the compare function is created

  • to compare 2 given argument's both being a string Value
  • and returning one of the following string Value's
    "It is a tie!"
    "paper wins"
    "rock wins"
    "scissors wins"

If you want to check on the validity of the user-input for the userChoice variable
you will have to create its owm function getUserChoice
in which you integrate the prompt AND do a check-on-validity.

As an example http://discuss.codecademy.com/t/9-9-next-steps/3746/2?u=leonhard_wettengmx_n


PS.
Please read:
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on

  • executing the compare function.

PS.
= https://www.codecademy.com/forum_questions/545154e280ff3349e9000496