-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion3.js
47 lines (40 loc) · 1.12 KB
/
question3.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const axios = require("axios");
const isMoreThenEighteen = (date) => {
return new Promise((resolve, reject) => {
let dateParts = date.split("/");
let today = Date.now();
let birthDate = new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]).getTime();
let major = 18 * 31557600000;
if (today - birthDate >= major) resolve("Is Major.");
else reject("Is Minor.");
});
};
isMoreThenEighteen("20/07/1999")
.then((result) => {
console.log(result);
})
.catch((err) => {
console.error(err);
});
async function execute() {
try {
console.log("Executing");
const firstPromise = isMoreThenEighteen("20/07/1999");
console.log(firstPromise);
} catch (err) {
console.log(err);
}
}
execute();
// Flemme de changer la fonction pour quelle marche pour la SWAPI
async function getUser() {
try {
const response = await axios.get("https://swapi.py4e.com/api/people/1");
isMoreThenEighteen(response.data.birth_year).then((result) => {
console.log(result);
});
} catch (error) {
console.error(error);
}
}
getUser();