New Steps


#1

Hello. First of all: english is not me native language, sorry for my mistakes. I want make my code some better and i faced with problem. If you can understand my code, please explain me why this code work after re-choose" paper,rock or scissors", when i choose something not "paper, rock or scissors":
var aa=1;
var userChoice=function(choice)
{
aa=choice;
console.log(choice);
if (choice != "paper" && choice !="rock" && choice != "scissors" )
{
userChoice(prompt("You should choose only 'paper', 'rock' or 'scissors'!!!"));
}
else
{
console.log("You choice: " + choice);
return choice;
}
};

var computerChoice=function(cc)
{
console.log("Computer: " + cc);
if (cc < 0.34)
{
console.log("Computer: Rock");
return "rock";
}
else if(cc <= 0.67)
{
console.log("Computer: Paper");
return "paper";
}
else
{
console.log("Computer: Scissors");
return "scissors";
}
};

var uc=function(a1)
{

a1=userChoice(prompt("The result is a tie! Make choice again!"));
return a1;

};
var cc1=function(b1)
{
b1=computerChoice(Math.random());
return b1;
};

var compare=function(a2,b2)
{
if(a2==="rock")
{
if(b2==="scissors")
{
return "Rock wins";
}
else
return "Paper wins";
}
if (a2==="paper")
{
if(b2==="rock")
{
return "Paper wins";
}
else
return "Scissors win";
}
if (a2==="scissors")
{
if(b2==="paper")
{
return "Scissors win"
}
else
return "Rock win";
}
};

var a=userChoice(prompt("Do you choose rock, paper or scissors?"));
console.log(aa);
var b=computerChoice(Math.random());
if(aa===b)
{
aa=uc(aa);
b=cc1(b);
compare(aa,b);
}
else
{
compare(aa,b);
}
/* I add two "console.log" like a point.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
And this code dont work, when i choose something not "paper rock or scissors".
In console write "undefined", when i want to print variable "a" after re-choose.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var userChoice=function(choice)
{
console.log(choice);
if (choice != "paper" && choice !="rock" && choice != "scissors" )
{
userChoice(prompt("You should choose only 'paper', 'rock' or 'scissors'!!!"));
}
else
{
console.log("You choice: " + choice);
return choice;
}
};

var computerChoice=function(cc)
{
console.log("Computer: " + cc);
if (cc < 0.34)
{
console.log("Computer: Rock");
return "rock";
}
else if(cc <= 0.67)
{
console.log("Computer: Paper");
return "paper";
}
else
{
console.log("Computer: Scissors");
return "scissors";
}
};

var uc=function(a1)
{

a1=userChoice(prompt("The result is a tie! Make choice again!"));
return a1;

};
var cc1=function(b1)
{
b1=computerChoice(Math.random());
return b1;
};

var compare=function(a2,b2)
{
if(a2==="rock")
{
if(b2==="scissors")
{
return "Rock wins";
}
else
return "Paper wins";
}
if (a2==="paper")
{
if(b2==="rock")
{
return "Paper wins";
}
else
return "Scissors win";
}
if (a2==="scissors")
{
if(b2==="paper")
{
return "Scissors win"
}
else
return "Rock win";
}
};

var a=userChoice(prompt("Do you choose rock, paper or scissors?"));
console.log(a);
var b=computerChoice(Math.random());
if(a===b)
{
a=uc(a);
b=cc1(b);
compare(a,b);
}
else
{
compare(a,b);
}


#2

You should put/change the if statement in a loop that only exits if you enter a valid choice.


#3

Can you make what you mean? Sometimes i have problems with understanding of the meaning english texts,becouse its not my native laguage. Thanks.