My task is to setup a number guess prompt which will return 1 of 3 values based on the guess. If the guess is the correct number it will return one value, if the guess is lower than correct number it will return another value and if its higher, another value.
I'm a complete noob at Javascript so any help would be greatly appriciated :)
This is my code so far:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Variables</title>
</head>
<body>
<script>
var userinput = prompt("Guess the number between 1-10");
var correctanswer = 7;
var incorrect1 = 8 && 9 && 10;
var incorrect2 = 1 && 2 && 3 && 4 && 5 && 6;
if (userinput == correctanswer) {
alert("Yay! You got it right");
}
if (userinput == incorrect1) {
alert("Your value is greater than correct value");
}
if (userinput == incorrect2) {
alert("Your value is lesser than correct value");
}
</script>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire