-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (60 loc) · 1.73 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
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) => {
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) => {
return `${value} cm`;
},
validate: (value) => {
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) => {
return `${value} kg`;
},
validate: (value) => {
if (value === "" ||
isNaN(value) ||
parseInt(value) <= 0 ||
parseInt(value) >= 727) {
return "Please enter a valid number between 1 and 727.";
}
return true;
},
},
])
.then((answers) => {
const bmi = calculateBMI(answers.weight, answers.height);
const category = getBMICategory(bmi);
console.log(`Hello ${answers.name}! Your BMI is ${bmi} and is considered as ${category}.`);
});