Joy and Marianna have written two different sets of code to accomplish the same goal of helping a caterer direct people with dietary restrictions to a menu item that works for them. Look at the code below.
Joy’s Code:
fun entree(diet):
if diet == "none": lasagna
else if diet == "gluten-free": salmon
else if diet == "kosher": salmon
else if diet == "lactose-int": salmon
else if diet == "nut allergy": lasagna
else if diet == "vegan": stir-fry
else if diet == "vegetarian": stir-fry
else: text("unknown diet", 20, "red")
end
end
Marianna’s Code:
fun entree(diet):
if (diet == "none") or (diet == "nut allergy"): lasagna
else if ((diet == "gluten-free") or (diet == "kosher")) or (diet == "lactose-int"): salmon
else if (diet == "vegan") or (diet == "vegetarian"): stir-fry
else: text("unknown diet", 20, "red")
end
end
Whose method do you like better? Why?
These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, and 1738598). Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.