samedi 30 mai 2015

else if function and arrays

I am trying to make a simple prompt function in javascript that will allow for two responses that both refer to separate arrays but when I open up the javascript document in console log, the only array that is recognized is the one for when the user inputs "no" in to the prompt box. And regardless of whether the user inputs "yes" or neither "yes" nor "no", the console log only refers to theKicker array and only prints out strings from theKicker. It won't print out strings from fieldGoal, neither will it print out "that's not the way! try again!" when the user inputs something that is neither "yes" or "no" in to the prompt box. Here is the code:

var arrayWoes= ["Ah what a buzzkill", "How dare you", "You are the worst", "I fart in your general direction", "How about you get out of town"];
var arrayYes= ["You marvelous user", "You must be pretty great. Welcome to   the fold.", "You are true of heart and steady of mind", "You're just a good one,   aren't you?"];
var theKicker= arrayWoes[Math.floor(Math.random() * (arrayWoes.length))];
var fieldGoal= arrayYes[Math.floor(Math.random() * (arrayYes.length))];
var select= prompt("Ready for an adventure?");
if(select= "no") {
    console.log(theKicker);

}
else if(select= "yes") {
    console.log(fieldGoal);

}
else {
    console.log("That's not the way! Try again!");

   }

I have combed over the code over and over again and tried to see if any errors existed and I looked over several sites (including the work I have been doing at Code Academy, w3schools, stack overflow forums, ect.) but I couldn't find anything that referred to my specific issue. Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire