Is there any reason why this code isn't working?
I have put the entire script into a function for the sake of the playAgain variable (see bottom) which would restart the function.
Any help would be much appreciated.
function headsTails() {
var userChoice;
userChoice = prompt('Heads or Tails');
function myGame(heads,tails) {
var result;
var coin;
result = Math.random()
if(result > 0.5) {
coin = "heads";
} else {
coin = "tails";
}
if(userChoice === "heads") {
if(coin = "heads") {
alert("You win!");
} else if(coin = "tails") {
alert("You lose!");
}
}
if(userChoice === "tails") {
if(coin = "heads") {
alert("You lose!");
} else if(coin = "tails") {
alert("You win!");
}
}
}
myGame();
var playAgain;
playAgain = confirm(Do you want to play again?)
if(playAgain) {
headsTails();
} else {
alert("Thanks for playing!")
}
}
confirm(Do you want to play again?)beconfirm('Do you want to play again?')?===in the conditions, immediately followed by=in the next condition.