-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculateAge.js
30 lines (28 loc) · 873 Bytes
/
calculateAge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function calculateAge(a, b) {
// enter your code here.
// return a > b ? `You will be born in ${a-b} years.`: a == b ? "You were born this very year!" :`You are ${b-a} years old.` if (a > b){
if (a > b) {
if (a - b == 1) {
return `You will be born in ${a - b} year.`;
} else {
return `You will be born in ${a - b} years.`;
}
} else if (a < b) {
if (b - a == 1) {
return `You are ${b - a} year old.`;
} else {
return `You are ${b - a} years old.`;
}
} else {
return "You were born this very year!";
}
}
console.log(calculateAge(500,360));
// other solution
const calculateAges = (a, b) =>
a < b
? `You are ${b - a} year${b - a > 1 ? `s` : ``} old.`
: a > b
? `You will be born in ${a - b} year${a - b > 1 ? `s` : ``}.`
: `You were born this very year!`;
console.log(calculateAges(500,350));