Learn JavaScript: Dog Years Project quirks

So, I’ve wanted to find a topic dedicated to this project but it seems like there are no active left. But I’m so curious that I have no other option other then to start a new one!

  1. While digging through the Dog Years Project, I was surprised by a necessity to use a string method .toLowercase(), as it converts all of the name letters to a lower case:
    What’s the purpose of doing that?
  2. And the other problem that I have encountered. By the end of this project we are being asked to try ANY human age and see what the result is. So I’ve tried “1” and it is not only doesn’t fit with the word “years”, but it actually gives us the wrong answer, 17 dog years instead of expected 10.5:

    I would understand if were told to try human age starting from 2 years old, but we were clearly told to try ANY human age:

Both of these question are equally interesting for me, hope some one can make it clear!:grinning:

  1. It is for making the code more flexible, so if someone tries to convert ages and you tell him to set the name there it will be lowercased.

  2. It throws an error because you subtract 2 from myAge so if myAge is 1 then it will be -1

Hope this helps :grinning:


Thanks for the reply!

  1. I understand what does the .toLowerCase do, the question is “why do we need the name to be lowercased?”
  2. It doesn’t throw any errors, it counts the dog years as 17 if my age is 1 year old(as shown in the screenshot above). Thus I consider it to be a mistake in the written code. We write a program to convert any human age to dog age. Because the program doesn’t do it’s job properly, I can say this program is bad, or has a bug, can’t I?

Good question. It leaves us all guessing, being right out of nowhere and for no good reason.

So we could see it, is the only one that comes to my mind.

When CC makes it a requirement that authors field technical questions like this, it will change the landscape. Until then we’re all abiding our own assumptions. Bottom line, test them all by whatever means.


So we could see what, the name?) But if it wouldn’t be lowercased, we would still be able to see it? I’m confused, am I just not very bright or I just don’t get the joke)
Anyways, thanks for the reply, it is a pleasure to be heard! :wink:

P.S. I’ve rewrote the program using else...if statement and now everything works just fine for any human age, even without lowercasing the name :yum: :

// introducing my name
let myName = 'Liliia';
// introducing my age
let myAge = 1;
// setting the variable representing dog age
let myDogAge = myAge;
// deciding which formula to use based on "My age"
if (myAge <= 2) {
  myDogAge *= 10.5;
} else {
  myDogAge = ((myAge - 2) * 4) + 21;
// deciding which sentence to print
if (myAge < 2) {
  console.log(`My name is ${myName}. I\'m ${myAge} year old which is ${myDogAge} years old in dog years.`);
} else {
  console.log(`My name is ${myName}. I\'m ${myAge} years old which is ${myDogAge} years old in dog years.`);

outputs: “My name is Liliia. I’m 1 year old which is 10.5 years old in dog years.”


Since it is a name it is pretty normal to save it as lowercase. If you want to for example compare a name with something else you don’t want to think about if the name has a capital or something. so generally the easiest way is to lowercase it on input.

This is just my view on using lowercasing. I think what @mtf means is that its a good question where there is no real answer to the question.
In this project tho i think it is just used for introduction. So you know it exists if you would ever find the need to use it.