I'm trying to create a higher number card game between me and an AI, but it always says the house wins, no matter what I input. If someone could help me figure out why my if, else statement isn't activating, I'd appreciate it.
<head>
<meta charset="UTF-8">
<!-- Extra Credit -->
<!-- Jordan Smith -->
</head>
<body>
<h1> Beat the House! </h1>
<script>
var num1 = prompt("Please enter a number between 1 and 10.", "");
var result = Number(num1);
num1 = parseFloat(num1);
{
document.write("</p>" + num1 + " is your number. </p>");
}
for(i=0; i < 1; i++){
var num2 = document.write(Math.floor(Math.random() * 10) + " ");
}
{
document.write(" is the house's number.");
}
{
document.write("<br>");
document.write("<br>");
}
if (num1 > num2) {
document.write("You have the higher number! You win!");
} else {
document.write("The house has the higher number! You lose!");
}
</script>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire