I'm having matching a user input with an element in the Array. "Index === lengthOfBoat" doesn't output "Works", even though the user input is matching a number in the Array. If I use a ">" sign, the console outputs "Works".
Thought this should be pretty simple.
What am i doing wrong?
var lenghtOfBoat = [4, 5, 6, 7, 8, 9];
var inputBoatLenght = document.getElementById("boatLenght");
inputBoatLenght.addEventListener("change", function() {
var index = lenghtOfBoat.indexOf(inputBoatLenght);
if (index === lenghtOfBoat) {
console.log("Works");
}
else {
console.log("Nooo");
}
})
<!DOCTYPE html>
<html>
<head>
<title>Båd Dækning</title>
</head>
<body>
<input type="number" name="boatLenght" id="boatLenght" placeholder="Båd Længde">
<input type="number" name="boatHK" id="boatHK" placeholder="Båd HK">
<script type="text/javascript" src="script.js"></script>
</body>
</html>
BR Martin