-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
54 lines (46 loc) · 1.33 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
#! /usr/bin/env node
import inquirer from 'inquirer';
async function askTable() {
const smallTable = await inquirer.prompt([
{
message: "Hello, I can provide tables from 2 to 20.",
type: "list",
name: "permission",
choices: ["ok"]
},
{
message: "Select one of the tables you want:",
type: "list",
name: "table",
choices: ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"],
}
]);
let tableValue: number = parseInt(smallTable.table);
if (tableValue >= 2 && tableValue <= 20) {
for (let i = 1; i <= 10; i++) {
console.log(`${tableValue} * ${i} = ${tableValue * i}`);
}
console.log(`This is a table of ${tableValue}`);
} else {
console.log("Invalid table value");
}
// Ask again for another table
askAgain();
}
async function askAgain() {
const answer = await inquirer.prompt([
{
message: "Do you want to select another table?",
type: "list",
name: "again",
choices: ["Yes", "No"]
}
]);
if (answer.again === "Yes") {
askTable();
} else {
console.log("Goodbye!");
}
}
// Start the process
askTable();