-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
68 lines (66 loc) · 1.74 KB
/
index.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import inquirer from "inquirer";
import { calculateBMI, getBMICategory } from "./bmi.js";
// TODO - Add chalk package (?)
console.log("---------- Welcome to the BMI calculator! ----------");
await inquirer
.prompt([
{
type: "input",
name: "name",
message: "What is your name?",
default: "John Doe",
validate: (value): string | boolean => {
if (!value.length) {
return "Please enter your name to proceed.";
}
return true;
},
},
{
type: "input",
name: "height",
message: "How tall are you? (in cm)",
default: "170",
transformer: (value): string => {
return `${value} cm`;
},
validate: (value): string | boolean => {
if (
value === "" ||
isNaN(value) ||
parseInt(value) <= 0 ||
parseInt(value) >= 272
) {
return "Please enter a valid number between 0 and 272.";
}
return true;
},
},
{
type: "input",
name: "weight",
message: "How much do you weigh? (in kg)",
default: "70",
transformer: (value): string => {
return `${value} kg`;
},
validate: (value): string | boolean => {
if (
value === "" ||
isNaN(value) ||
parseInt(value) <= 0 ||
parseInt(value) >= 727
) {
return "Please enter a valid number between 1 and 727.";
}
return true;
},
},
])
.then((answers): void => {
const bmi: string = calculateBMI(answers.weight, answers.height);
const category: string = getBMICategory(bmi);
console.log(
`Hello ${answers.name}! Your BMI is ${bmi} and is considered as ${category}.`,
);
});