-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHowOld.js
More file actions
22 lines (16 loc) · 602 Bytes
/
Copy pathHowOld.js
File metadata and controls
22 lines (16 loc) · 602 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Write your function here:
function howOld(age, year){
let currentDate = new Date();
let theCurrentYear = currentDate.getFullYear();
let yearDifference = year - theCurrentYear;
let newAge = age + yearDifference;
if (newAge < 0) {
return `The year ${year} was ${-newAge} years before you were born`
} else if (newAge > age) {
return `You will be ${newAge} in the year ${year}`
} else {
return `You were ${newAge} in the year ${year}`
}
}
console.log(howOld(39, 1900));
// Once your function is written, write function calls to test your code!