JavaScript - Dog Years Project

Hi coders, :raising_hand_woman:

I have completed Dog Years project.

However there’s an suggestion at the end of the project that " If you’d like extra practice, try writing this project without the *= operator."

Does this mean without only *= operator or writting this project without using mathematical operators (+=, -=, *=, =).
If it can be written without using mathematical operators, then I still can’t think a way to do the project.
Any opinion? Thanks

I think they mean still using the mathematical operators, just not using specifically *=

For example,
you might do
n = n * 2;
instead of doing
n *= 2;

project link: https://www.codecademy.com/projects/practice/dog-years-javascript

2 Likes

Can you link the project?

You could precalculate the dog year equivalencies - not an unreasonable task, since, depressingly, dogs don’t live that long. You’d store the results in an array or object and then return the results depending on the input year.

For example,

function dogYearsToHumanYears(dogAge) {
    const dogToHumanAgeMap = {
        1: 15,
        2: 24,
        3: 29,
        4: 34,
        5: 39,
        etc.
}

At this point, I realized my oldest boy is basically 39 and decided to stop thinking about it :frowning:
But anyways, that’s one way you could do it. By the way, the equation I used for that is from: https://www.akc.org/expert-advice/health/how-to-calculate-dog-years-to-human-years/

1 Like

Hi there, :raising_hand_woman:

Your answer is a good way of thinking. :+1:

After posting this, I thought again about the task…something about my dumb head because this task must involve with mathematic calculation in order to convert the age. I though I would delete this post but I think who knows some else come up with solution without mathematical operators.

Thank you for your contributing to my question. :smiley:

Hey you :raising_hand_woman:

Your written code to answer my question is interesting and I am trying to understand it.
I am new to JavaScript and a slow learner therefore I have not learnt about array yet or how to store the value in an array. I hope to learn about array soon.

It looks like your oldest boy is over 6 years old. :dog2: .

Thank you for your input. :cake: :smiley:

Here is the link of the project.

https://www.codecademy.com/courses/introduction-to-javascript/projects/dog-years-javascript

Ah, well, welcome to the world of programming.

Programming isn’t the easiest thing to learn, even with Codecademy’s excellent curriculum, so maybe you’re not a slow learner. Take your time with the program you’re doing, and be patient. It can sometimes feel frustrating to get stuck on a problem, but you will figure it out. And if you need help, come to the forums and make sure to link what you’re working on and describe the problems/errors you’re having in good detail.

1 Like

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