Challenge 15 Megathread

Welcome to challenge #15!

Use this thread for any and all questions relating to challenge 15



In the above example, the difference comes out as 9 days. Shouldn’t it be 11? Or am I not understanding how the rounding should occur?

Hey there! It’s a typo that has been corrected if you refresh!


I did it))) Thank you LHL-Team))

Hello! I’ve also passed this task but only after console.log of inputs. It’s kinda hard to understand: are years and months the same? or they are different? if they were, it would be a little bit more of work:)

I refactored my code as I realized that for this function it should not matter what input is, it must be universal for any date.

Larry should perhaps offer the hint that the number of milliseconds in a day is (1000 * 60 * 60 * 24) or 86400000, otherwise very good challenge.


What is the difference between setting up a date like it was done in line 3

const today = fakeToday || new Date();

vs. new Date(‘date value’)

const launch = new Date (launchDate);

my code didnt work until i switched the way i saved launchDate to the latter one


If you do

new Date(today)

it will make today a Date object. This way you can use built-in functions whether or not ‘today’ was passed to the function as a string or it was created as a new Date within the function.


I got curious after you posed this question and added a bunch of console.log outputs to my code. It seems that const today = fakeToday || new Date(); checks if fakeToday is false-y. If it is, today becomes the current date/time.

Doing some more research I found this link explaining how the above functions:

"expr1 || expr2 Returns expr1 if it can be converted to true; otherwise, returns expr2. Thus, when used with Boolean values, || returns true if either operand is true; if both are false, returns false."


Today’s code was more challenging . Thank you!


Thank you for today’s challenge seems uncoquerable at first but we did it y’all day 15 in the bag :joy: :dancer:

1 Like

Glad I recently learned about .getDate()

1 Like

Just some feedback on the challenges:

I found it a little annoying guessing what the data types are, where launchDate is a string with a date in it (Which to me doesn’t make a ton of sense since it has ‘date’ in the variable name), and faketToday is a date (Although it does get converted to a string). However, instead of using a string for date information, why not use the date object? Seems to make a little more sense since we are dealing with dates.


Reviewing the Instructions I noticed that it requires a “rounded day difference”.

The difference between two dates (which do not include fractions of a day) expressed in ms does not require rounding after conversion to Days.

What am I missing?

Hi there!

It was specified in the instructions that both the launch date and name are strings (fakeToday is a date object)

It seems annoying to convert the date string to a date object when we could receive a date object directly, and you’d be right! However, dates are not a standard structure and if you have to interact with other scripts, apis or data, you will receive it as a string, so it’s actually a common thing to do.


launchDate, missionName, fakeToday are all provided as strings. As can be observed in the example input, and explicitly stated in the day’s write-up.

fakeToday gets converted to a Date on the first line as a sort of example how you might work with a string that needs to be converted to a date.

Converting between data types is a common requirement in coding, especially in projects where you may only be responsible for a small portion of the code. Normalizing your inputs, thus, is often a requirement, and a good practice to avoid certain types of code failures.

So step 0) receive string, step 1) convert to usable types (several ways to do this) step 2) embed the result in an object. Step 3) return the object.


I believe it is specified because if you are dividing the number of Milliseconds in a day as seen in the code below (where lDate is the Date object for launchDate and tDate is the same for today).
(lDate.getTime() - tDate.getTime())/(1000 * 60 * 60 * 24)
You can possibly get a floating point result (though based on my initial test which passed, it is not being checked for).

If fakeToday is passed with the same format as the example, this is no issue, however if the new Date() executes in the first line of the function, this can in fact happen.

Case in Point:

For this result I have removed the Math.round() from my code.

As per Sonicthecronic’s suggestion in Post: Challenge 15 Megathread - #21 by Sonicthecronic, I have modified my code to use Math.trunc() instead as Math.ceil() would indicate 1 day remaining even if it is the day of the launch.

1 Like

this one got me thinking a lot ! Good challenge !

The problem says the expected output is:
missionName = “Moon visit”,
daysRemaining = 11

That’s not an object . Don’t you mean this:
missionName: “Moon visit”,
daysRemaining: 11

1 Like