Learn

You may have run across modulo, symbolized as the percent symbol %, before. If not, or as a reminder, modulo performs division but instead of giving you the number of times the denominator goes into the numerator, it gives you the remainder after the division. As an example, if you took 10 / 3 you would get 3 with 1 left over. If you wanted to just get the remainder and didn’t care about the other part you would do 10 % 3. This would give you 1.

A common use of modulo is determining if an integer is even or odd. If we have an integer, x, and aren’t sure if it’s even or odd, we can use modulo to see the remainder. If the result is 1, x is odd, otherwise it is even.

Instructions

1.

Modulo can also be used to determine the day of the week given a start and end day. For our exercise, we are going to assume that we are starting on the first (represented by 0) day of the week and we want to figure out if n (program starts at 13) days go by, what day of the week is it now.

For the first step, set the initial values for daysThatPass (any positive integer you like) and daysInWeek (7) during their declaration.

2.

Your task is to use modulo logic to determine the day of the week it will be after n days pass.

Store the result in endingDayOfWeek. If you need help figuring out what you would need to do to calculate this take a look at the hint.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?