Having a bit of trouble with my if
else
structure. When I enter the correct star name like "Vega", it incorrectly shows me "Error" instead of the expected result "Lyra".
Here's my code snippet:
var stars = ["Polaris", "Aldebaran", "Deneb", "Vega", "Altair", "Dubhe", "Regulus"];
var constellations = ["Ursu Minor", "Taurus", "Cygnus", "Lyra", "Aquila", "Ursa Major","Leo"];
function checkArrays() {
for (n = 0; n < 7; ++n) {
if (test.inputStars.value == stars[n]) {
test.inputConstellations.value = constellations[n];
} else {
test.inputConstellations.value = "Error";
}
}
}
<!DOCTYPE html>
<html>
<head>
<title> Array structures</title>
</head>
<body>
<form name="test">
<input type="text" name="inputStars">
<input type="button" onclick="checkArrays()" value="Find constellation">
<input type="text" name="inputConstellations">
</form>
</body>
</html>