Welcome to BHS Computer Science. If you are a student in the class, the first thing you need to do (and which we should have done in class) is set up your GitHub account.
Once you have a GitHub account, click “Log in to GitHub” below to proceed. Or you can click “Use anonymously” to play with the environment but you will not be able to save your work or submit assignments. (You can always log in later by clicking the at the top of the page.)
If you don’t have a GitHub account yet, please create one and then log in here for further instructions.
Congratulations! You have successfully connected this app to GitHub. However you are not yet a member of the GitHub organization for this class, something Mr. Seibel needs to set up for you.
This is your GitHub profile URL:
Click the clipboard icon to copy it and then submit it at this form so he can add you.
Congratulations! You have successfully connected this app to GitHub. And it looks like you have an invitation to join the GitHub organization for this class. You need to accept that invitation before you can proceed. The invite should be sent to whatever email you used when you created your GitHub account.
I see you are logged into GitHub and a member of the berkeley-high-cs GitHub organization. However there seems to have been some problem finishing the setup for your account. Please let Mr. Seibel know.
This is a tool for the BHS Computer Science class at Berkeley High School. It is intended to provide a simple environment for experimenting with Javascript without all the complexities of a full development environment such as ReplIt or Glitch which we may use later in the year.
It is also designed to take advantage of the browser’s ability to run Javascript natively. It does not need access to a server to run code making in extremely responsive even if the Wifi is flaking out.
Finally, under the covers it is saving work to a GitHub repository in a very simplified workflow that does not depend on immediately learning any git commands. Code written in this environment for each assignment is saved to a directory and branch specific to that assignment each time it is saved. Thus when the assignment is done, it is easy to go to GitHub and create a PR containing just the work on that assignment which can then be commented on and worked on further before it is turned in and merged to main.
You're all set! You don't need to worry about this yet but we have successfully created a GitHub repository for your work:
You can get to it any time by clicking on your GitHub username at the top-right of the screen.
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:
Math.floor()
which takes a single argument and returns
the largest whole number less than the given value. For instance,
Math.floor(1.3)
returns 1
.
Math.max()
which takes any number of numbers as
arguments and return the largest of them. For instance,
Math.max(0, -3)
returns 0
since it is
larger than -3
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!
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.