mercredi 20 février 2019

How do I change the evaluation of the expression in the conditional to check for a boolean in Javascript?

I'm creating a coin flip game, and the very last step is to use a math methods to get a solid number on the coin flip. Then change the evaluation of the expression in the conditional so that it checks for a boolean. What are some ways I can achieve this? What am I doing wrong?

var coinFlip = Math.random();
var choice = window.prompt("Select heads or tails");
if (coinFlip < 0.5) {
    choice === window.console.log("heads");
} else {
    choice === window.console.log("tails");
} if (choice === "heads" && coinFlip < 0.5) {
    window.alert("The flip was heads and you chose heads..you win!");
} else if (choice !== "heads" && coinFlip < 0.5) {
    window.alert(" The flip was heads and you chose tails...you lose!");
} else if (choice !== "tails" && coinFlip > 0.5) {
    window.alert("The flip was tails but you choose heads...you lose!");
} else if (choice === "tails" && coinFlip > 0.5) {
    window.alert("The flip was tails and you chose tails...you win!");  
}
coinFlip = Math.Round(Math.Random);
coinFlip = Boolean(choice);

strong text

Aucun commentaire:

Enregistrer un commentaire