Cool, good job. I think working on little side projects like this are a great way to learn.
If I put on my code review hat… and please keep in mind that I am a picky reviewer…
You use let
a lot when you should be using const
. Only use let
with primitives that you need to change or reference types that you will need to reassign.
You should indent your if
statements. Formatting your code is extremely important - develop good habits early.
let daysOld = parseInt(difference / 1000 / 60 / 60 / 24);
Try to avoid “magic numbers”. Those numbers have no meaning on their own, I have to read it and figure it out. Imagine having to read through tens of. thousands of lines of code - every little speedbump can be frustrating. Putting something like:
const MS_IN_DAY = 1000 * 60 * 60 * 24;
somewhere out of the way and then using it:
let daysOld = parseInt(difference / MS_IN_DAY);
makes the code more readable. True, what you had may be kind of borderline on readability, but it’s a good habit to get into.
`
<h2>Congratulations!</h2>
<p>You are <span class="blue-text">${daysOld}</span> days old!</p>
<button type="button" id="clear-btn">Clear</button>
`;
What if they enter a date that is yesterday? True, it’s an edge case and unlikely, but these are the kinds of things that programmers have to think about. What about:
`
<h2>Congratulations!</h2>
<p>You are <span class="blue-text">${daysOld}</span> ${daysOld === 1 ? 'day' : 'days'} old!</p>
<button type="button" id="clear-btn">Clear</button>
`;
You could also do that logic earlier and store that string in a variable.
I don’t see anything else that jump out at me.
Oh, and one more question: would this kind of small project go on a portfolio? Or is this still to small and simple for that?
I would think that this is probably too small and simple. But if that is the best you have so far, put it on there and then keep building newer and better apps. But I like your initiative - when I was applying for jobs, I think the apps that I came up with (instead of curriculum projects or tutorial things) where the ones that attracted the most attention. So, I think you’re on the right path.
Good work.