9. Next Steps


#1

I try to solve

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

by use this function

var chooseOne = function(choice){
if(choice!=="rock"){
if(choice!=="paper"){
if(choice!=="scissors"){
return "You have to choose 1 choice";
choice = prompt("Do you choose rock, paper or scissors?");
}
else{
console.log("user: "+ choice);
}
else{
console.log("user: "+ choice);
}
else{
console.log("user: "+ choice);
}
};

What's wrong with my function?


#2

@rapeewan,

var chooseOne = function(choice){
 if(choice!=="rock" && choice!=="paper" && choice!=="scissors"){
   console.log( "You have to choose 1 choice" );
   choice = prompt("Do you choose rock, paper or scissors?");
   console.log("user: "+ choice);
 }
 else{
 console.log("user: "+ choice);
 }
/*
else{
 console.log("user: "+ choice);
 }
 else{
 console.log("user: "+ choice);
 } 
*/
};

chooseOne("dog");
chooseOne("paper");