Moon phases (Math Operators II)


#1

In the modulus excercise with moon phases it it assumed that it’s full moon - that is day 14 into the cycle.

How does

console.log(365/27);
console.log(365%27);

help if it’s currently, let’s say day 6 into the cycle?

This doesn’t really demonstrate how modulus can be useful for that problem because the answer 14 to me seems coincidental because the current day (14 or 6 or other) isn’t even provided in the formula.

Edit:
I understand that part how it’s supposed to work.
My point was that this excercise does not effectively demonstrate how modulus can be useful for getting to know what moon phase will be in a year.

Namely, which moon-day will it be in a year if it’s currently day 6 (NOT day 14)?
How does the code provided help us if it’s day 6, not day 14?

Note: the current day (full moon as assumed in the excercise - that is day 14, or 6 or whatever day) is not even included in the formula - which means the current day does not change anything, therefore it is a coincidence that it happens to be number 14, which ultimately means it is a bad example of the usefulness of modulus.


#2

@mhpreiman,

console.log(365/27);
console.log(365%27);

It prints:

13.518518518518519
14

The first one:

console.log(365/27);

tells us how many times the moon circles the Earth in 365 days. (For every 27 days).

Answer:

13.518518518518519

13 times/ or 13 cycles. (followed by a decimal(.518…), this decimal means an incomplete cycle in which it doesn’t reach one full cycle.)


Next

console.log(365%27);

tells us how many days left after the moon circles the Earth for 13 cycles.
13 cycles x 7 = 351 days, after 13 cycles, the moon is back to where it is.

Answer:

14

to reach 365 days, the moon still have to circles the Earth for the rest of 14 days.

So based on the diagram:

https://s3.amazonaws.com/codecademy-content/courses/javascript-101/img/moonPhases.svg

You count the extra 14 days after the 13 cycles (351 days = moon back to where it is) in order to know what moon it will be a year from now (365 days later):

  • If it is full moon now (today), follow the diagram, add 14 steps/days, you will reach new moon in a year (365 days) from now.

  • If it is new moon now (today), follow the diagram, add 14 steps/days, you will reach full moon in a year (365 days) from now.

Hope it helps :slight_smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.