Click to reopen instructions.

This assessment consists of functions you need to write involving primarily numeric expressions. It is a closed book assessment. You should stay on this tab until you are done and there should be no talking. This assessment is about how much you understand. There are no automatic tests but you can use the REPL to test things yourself.

You can move through the questions with the arrows at the upper right next to the 1 of indicator so if you’re not sure how to write one function move on to another one and come back if you have time at the end. I want to see how much you do know. Note: you can also click on thingsLikeThis in these instructions and the questions to copy them to the clipboard to avoid spelling mistakes. (I.e. click to copy and then ⌘-v to paste wherever you want.)

Two useful functions you might want to use in some of these questions:

When you are done, please click on your Github username above and submit a GitHub pull request of the branch and request me as a reviewer. Doing this correctly is part of the assessment. If you are unsure how to request a review, please ask for help!

Put definitions here.

Revisions:

Questions of

Write a function named totalEggs that takes two arguments, a number of hard-boiled eggs and a number of soft-boiled eggs you want to make and returns the total number of eggs you need.

Write a function named chocolatesPerPerson that takes two arguments, a number of chocolates and a number of people. Return the largest whole number of chocolates you can give to each person if everyone gets the same amount. For instance, chocolatesPerPerson(13, 5) should return 2.

Write a function named extraChocolates that takes two arguments, a number of chocolates and a number of people. Return the number of chocolates that are left over after distributing the chocolates evenly to all the people. For instance, For instance, extraChocolates(13, 5) should return 3.

Write a function named leftOut that takes two arguments, a number of chocolates and a number of people. Return the number of people who won’t get a chocolate if you try to distribute them evenly and there are more people than chocolates. However, if there are enough chocolates for everyone to get at least one the function should return 0. For example, leftOut(10, 13) should return 3 but leftOut(13, 10) should return 0.

Write a function named probabilityAllHeads that takes a single argument specifying the number of times a coin will be flipped and returns the probability (a number between 0 and 1, inclusive) of getting all heads. For instance probabilityAllHeads(1) should return 0.5 since the chance of getting heads on one toss is 1/2. And probabilityAllHeads(2) should return 0.25 since the chance of two independent outcomes—such as getting a head on each of two flips of a coin—both occuring is the product of their probabilities, in this case 0.5 × 0.5 = 0.25. For reference probabilityAllHeads(10) should return 0.0009765625.

Write a function named futureHour that takes two arguments, the current hour on a 24-hour clock, i.e. a number from 0-23 inclusive, and a positive number of hours in the the future that an event will occur. Return the hour it will be when the event occurs. For example, futureHour(9, 4) should return 13 since four hours after 9 it will be hour 13. Note that the number of hours can be arbitrarily large: futureHour(9, 28) would also return 13 since the event would occur at hour 13 the next day.

Write a function named presentsBudget that takes two arguments, the number of friends you are buying presents for and the average price of present you plan to buy, and returns the total amount of money you expect to spend. For instance presentsBudget(6, 15), i.e. six friends on whom you want to spend an average of fifteen dollars, should return 90.

Write a function named perPresent that takes two arguments, the total amount of money you have budgeted for buying presents and the number of presents you need to buy, and returns the average amount you can spend per present. Thus perPresent(90, 6) should return 15 since with a budget of ninety dollars and six presents to buy, you can spend an average of fifteen dollars per present.

Write a function named wrapingCombos that takes three arguments, the number of kinds of wrapping paper you have, the number of kinds of ribbions you have, and the number of kinds of decorative bows you have. Return the number of different combinations of paper, ribbon, and bow you could produce, using one kind of paper, one kind of ribbon, and one bow to wrap a present. For example, with just two kinds of paper, three kinds of ribbon, and five different bows there are thirty combinatons: for the two kinds of paper you can choose any of the three ribbons, giving six paper/ribbon combinations. And each of those combinations can be topped with one of five different bows, giving thirty total combinations. Thus wrappingCombos(2, 3, 5) should return 30.

Write a function named biggestNumber that takes a single argument representing a number of digits and returns the largest number that can be written in our ordinary decimal (base-10) number system using that many digits. For instance:

  • biggestNumber(1) should return 9
  • biggestNumber(2) should return 99
  • biggestNumber(3) should return 999

Hint: As a starting point, you might want to think about the numbers one bigger than these numbers and how you could express them in terms of the desired number of digits.

REPL