mardi 24 janvier 2017

Why doesn't my javascript if statement target the array?

When I enter Archers, Skeletons, or Balloon into the prompt, it only displays the else alert statement. I am not sure what I am doing wrong,why doesn't the if target the array? can anyone explain or give tips?

Thank you

HTML with script:

<html>
  <head>
    <title>challenge 1</title>
  </head>
  <body>

<script>
var nameCost;
nameCost = [3,6,7];
var nameList;
nameList = ['Archers','Sparky', 'Pekka']
var question = prompt('What is your card name?');

  if (question.value == nameList[0])
  {
    alert('Your name cost is ' + nameCost[0]);
  }
  else if (question.value == nameList[1])
  {
    alert('Your name cost is ' + nameCost[1]);
  }
  else if (question.value == nameList[2])
  {
    alert('Your name cost is ' + nameCost[2]);
  } else {
    alert('Your name and card is not available');
  }


</script>
  </body>
</html>

Aucun commentaire:

Enregistrer un commentaire