samedi 28 mars 2020

Only the first if statement is returning (if / else if / else)

function getDrinkByProfession(param){
if (param = "Jabroni"){
return "Patron Tequila";
} else if (param = "School Counselor"){
return "Anything with Alcohol";
} else if (param = "Programmer"){
return "Hipster Craft Beer";
} else if (param = "Bike Gang Member"){
return "Moonshine";
} else if (param = "Politician"){
return "Your tax dollars";
} else if (param = "Rapper"){
return "Cristal";
} else {
return "Beer";
}
}

The input to this function (param) should return the suitable drink for each customer, with an else statement to cover any exceptions.

When this code is tested only the first if statement returns correctly and all other inputs to the function return "Patron tequila" (the first if statement's return value).

Aucun commentaire:

Enregistrer un commentaire