Hey guys, I'm making a javascript rock, paper, scissors game! So the code is below and it doesn't work the alerts isn't showing and I really don't know where I mess things up.
function randomNumber(x,y){ //returns a random number from an interval given
var z;
if (x>y) {z=x; x=y; y=z;} // turns the interval upside down if the numbers of the interval are entered in unconsecutive order
else if(x==y) {return x; break;} //if there's no interval but two same digits return the number entered
var randomNo = (y-x)*Math.random() + x; // the random value itself in float type
Math.round(randomNo); // round it to integer
}
function outcomeType(value){ //gives the type of hand-symbol in game for each player according to the random No given
var outcome;
if (value==1 || value==4){outcome="rock"} //value 1 or 4 gives rock, same way with other two...
else if(value==2) {outcome="paper"}
else {outcome="scissors"}
return outcome;
}
function result(x,y){ // compares the numbers so that a winner is decided
if(x>y){return 1} //player A wins
else if(x==y){return 0;} //draw
else {return 2} //player B wins
}
function game(){
var a=randomNumber(1,3); // random number for player A
var b=randomNumber(1,3);// random number for player B
if(a!=2 && b!=2 && a!=b){ //the case rock-scissors, rocks from 1 beecomes 4 in order to beat in result()
if(a>b){b=4}
else{a=4}
}
var winner = result(a,b); // we have a winner!!!
if (winner==1) {alert("Player A wins with"+outcomeType(a)+"against"+outcomeType(b););} // the alert should be like: Player A wins with "scissors" against "paper"
else if (winner==0) {alert("Draw with"+outcomeType(a););} //draw
else {alert("Player B wins with"+outcomeType(b)+"against"+outcomeType(a););} //player B winning alet
}
Appreciate any help