So I have worked in IT for about 7 years now, however I never got into a position that involved a ton of coding. I like it to code, but am just a hobbyist at the moment, just to give you some understanding of my level of coding proficiency.
I am trying to create an HTML page that has some text before an input box, followed by a button. The button will perform a function on click, I want this function to take the input and run it against an array, if the item exists in the array, then I want it to print a specific message. This message is different for each item in the array.
To give you an idea of what I am doing, this is for my Dungeons and Dragons game, running the curse of strahd there is a part where a sequence of card draws are made to help you through the adventure. so say they draw a card, I put the word "Avenger" in the input box, it does exist in the array, I then want it to print "The treasure lies in a dragons house, in hands once clean, now corrupted." I know i could just write it all down, but i thought I would make a fun project of it. I have cobbled together what I think should work however when I press the button nothing happens.
<script>
var LowCards ["avenger", "paladin",}
the array is there, populated with about 40 names, avenger, paladin, warrior, rogue, enchanter etc.
function CARD1()
{
var card1 = document.getElementByID('card1').value;
if(CARD1.indexOf("avenger") !== -1){
alert("The treasure lies in a dragons house, in hands once clean, now corrupted.")
} else if{CARD1.indexOf("paladin") !== -1){
alert("I see a sleeping prince, a servant of light and the brother of darkness. The treasure lies
with him.")
}
etc, etc, through the whole list of 40 until this last statement which says, if it isnt there tell them it doesnt exist.
else{
alert("Value does not exists!")
}
}
</script>
So the function is declared before the body, in the body I try to pull the fucntion with the button
<input type="text" id="card1" name="card1"=>Enter the name of the first card drawn</input>
<button onclick="CARD1();">Submit</button>
</p>
Your logic is a little messed up. indexOf will return positive number whenever the input is found in the array. Thus only the first if statement will get executed. The map function is a good way to go but if you are just starting out basic programming will do the trick. Objects have keys and attributes. Consider: