-
Notifications
You must be signed in to change notification settings - Fork 0
JavaScript Bind()
You are the restaurant manager at the Guardalavaca resort, on Cuba's most beautiful beach. A planeload of German tourists has arrived, and planeload of Korean tourists. You consult the new web app that the Cuban military has developed for resort management. (The Fuerzas Armadas Revolucionarias run the tourism industry in Cuba.) The web app tells you to serve sauerkraut to the Germans and serve kim chee to the Koreans.
All goes well until you see a Korean man seated with the Germans. You signal for the tour guide to speak to you. She explains that Herr Kim's parents were Korean but he was born in Germany, speaks only German, and has never been to Korea. You query the web app as to whether Korean-Germans should be served sauerkraut or kim chee, but the app returns undefined. You and the tour guide discreetly approach Herr Kim and ask his cabbage preference. "Bitte kim chee, danke!" he enthusiastically responds.
In hopes of furthering your career you contribute a new method to the code base. You find this code:
var cabbagePreference = function(nationality) {
if (nationality === "German") {return "Serve sauerkraut to Germans."};
if (nationality === "Korean") {return "Serve kim chee to Koreans."};
if (nationality === "American") {return "Serve cole slaw to Americans."};
...
}
You want to write something like this:
if (nationality === "Korean" && "anything else") {return "Serve kim chee."};
How do you write this line?