Danny WOD: Sharky’s Appetite

Sharky is a Great White Shark that frequents a local pier. He is a favorite among the people there, although he has a huge appetite and will sometimes cause trouble when he does not have enough to eat. He loves fish, but will occasionally eat trash by accident (which he absolutely hates…). Create a function that simulates a day that Sharky goes through based on what he eats. The function will take in an array of strings which represents what Sharky has eaten throughout the day, and will then print out a description of Sharky’s mood for each food type.

The specifics for the function is as follows:

  1. The function should take in an array of strings.

  2. For each string in the array, the function should perform the following:

    • If the string is “fish”, then print out “Sharky ate some fish and is happy!”
    • If the string is “trash”, then print out “Sharky ate some trash and is mad!”
    • If the string is “other”, then print out “Sharky is starving…”
  3. If Sharky has eaten at least 4 fish for the day, then print out “Sharky is very satisfied.” If he has not eaten at least 4 fish, print out “Sharky is on a rampage!”

So, for example, if the input array is ['fish', 'fish', 'trash', 'other'], then the output should be:

Sharky ate some fish and is happy!
Sharky ate some fish and is happy!
Sharky ate some trash and is mad!
Sharky is starving...
Sharky is on a rampage!

Ready? Let’s begin:

  1. Login to JSFiddle.

  2. Create a Javascript function called “SharkyAppetite”. Make sure the function follows the specifics above.

  3. Informally test your program by running it and inspecting the output. Test the program using the following two arrays:

    • [‘fish’, ‘fish’, ‘trash’, ‘fish’, ‘trash’, ‘fish’]
    • [‘trash’, ‘fish’, ‘trash’, ‘other’, ‘trash’]
  4. When you are confident the function works correctly, press “Save” to create a URL to your JSFiddle.

  5. Raise your hand to let me know you have finished.

Rx: < 8 min Av: 8 - 12 min Sd: 12 - 15 min DNF: 15+ min

Submission instructions

You do not have to submit this Danny WOD.


This page is also available via http://goo.gl/XExSZN