My question is what happens if my age is less than 2? When I set my age as ‘1’ the calculator show my dog age is 17 instead of 10.5, because we define the later years as ‘myage - 2’ so basically in this case it will be -1, and then -1*4 = -4. Is there any formula which ignores the negative value? like “IF” or something like that.

Is there something wrong with if? If not, use it, right? Or if there is, then, what? That would say something about what you’re after.
Or are you asking what should be done for lower amounts? You could google “dog years”

Here it is. With ‘33’ it works perfectly. If you use ‘1’ as myAge, the calculation is wrong:

const myAge = 33; // This is my age
let earlyYears = 2; // this is the early years
earlyYears *= 10.5;
let laterYears = myAge-2;
laterYears *= 4;
console.log(earlyYears)
console.log(laterYears)
let myAgeInDogYears = earlyYears+laterYears;
let myName = ‘John Dog’.toLowerCase();
console.log(My name is ${myName}. I am ${myAge} years old in human years which is ${myAgeInDogYears} years old in dog years.)

If there’s an immediate automated way to find something out, surely that is something to try before looking for people

people are good for when you don’t know how to continue from where you are

and, if someone asks something that can be googled I get very confused about what they’re looking for, surely it’s not the thing they can google, must be something else, but what?

and arguably almost any question around exercises should probably be in terms of “how do I find this out/how do I approach this problem” because the real problem is the method for getting to the result, the result itself is something trivial and worthless

You are right. I wrote to the forum because I was looking for some human interaction, especially because I thought this information could be useful for others as well. I am sure I am not the only one who faced this ‘issue’ or had this question in their mind.

While on the topic of perspective, your human perspective on a problem is often very useful as humans tend to solve a lot of problems unconsciously. If you figure out/describe how YOU would do something, then you’ve probably laid out an algorithm right there, and then you can write that down.

One approach to this dogyears problem is to have two expressions, one for young dogs and one for old ones, and you’d use an if-statement to decide which to use.

Another approach is to see the age as two parts, the first two years and the rest. They have different multipliers to them and are then added:

dogYears = earlyYears * 10.5 + lateYears * 4

earlyYears would be the full age but at most 2, so one would pick the smallest of these two values
lateYears would be the full age minus 2 but at least 0, so one would pick the largest of these two values

The functions Math.max and Math.min could be used to figure those out, and then a single expression that covers the full possible range has been obtained.

But I didn’t start out by thinking that I want to solve it with min/max functions, I decided what I wanted to do first, and then started looking for matching parts in the language.