javascript - else if function and arrays -


i trying make simple prompt function in javascript allow 2 responses both refer separate arrays when open javascript document in console log, array recognized 1 when user inputs "no" in prompt box. , regardless of whether user inputs "yes" or neither "yes" nor "no", console log refers thekicker array , prints out strings thekicker. won't print out strings fieldgoal, neither print out "that's not way! try again!" when user inputs neither "yes" or "no" in prompt box. here code:

var arraywoes= ["ah buzzkill", "how dare you", "you worst", "i fart in general direction", "how out of town"]; var arrayyes= ["you marvelous user", "you must pretty great. welcome   fold.", "you true of heart , steady of mind", "you're 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 adventure?"); if(select= "no") {     console.log(thekicker);  } else if(select= "yes") {     console.log(fieldgoal);  } else {     console.log("that's not way! try again!");     } 

i have combed on code on , on again , tried see if errors existed , looked on several sites (including work have been doing @ code academy, w3schools, stack overflow forums, ect.) couldn't find referred specific issue. appreciated.

your if statements assigning variable, not checking it.

you want if(select == 'no')

when if(select = 'no') assign 'no' select var, , in javascript not null, undefined, or false truthy (meaning interpreted true)

while in case == fine, best practice use === see equality comparisons , sameness


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -