I'm not a professional coder, and I have an issue that might have a very simple fix.
So here is my code so far. It is very basic. I'm trying to get the code from the html input, and use that to carry out the javascript. For example, if a person types "Hydrogen" into the input, I want it to take them to a hydrogen page, but if they type in "helium", I want to take them to the helium page. Here's the code that I have written, but everytime I try it, no matter what I type, it takes me to the helium page. Can anyone please help me fix this issue. Thank you
<body>
<input id="search" placeholder="Search for an element">
<button>Search</button>
</body>
<script type="text/javascript">
document.querySelector("button").addEventListener("click", function() {
if (document.getElementById('search').value === 'Hydrogen'||'H'||'1') {
window.location.href='./elements/hydrogen.html'
}
if (document.getElementById('search').value === 'Helium'||'He'||'2'){
window.location.href='./elements/helium.html'
}
})
</script>
<script src="...." async defer></script>so that it doesn't block the main thread while it gets downloaded, and doesn't run until the document has finished being turned into a DOM.if (['Hydrogen', 'H', '1'].includes(document.getElementById('search').value))