-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (69 loc) · 1.86 KB
/
index.js
File metadata and controls
76 lines (69 loc) · 1.86 KB
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
69
70
71
72
73
74
75
76
//external modules
import inquirer from "inquirer";
import chalk from "chalk";
//internal modules
import fs from 'fs';
operation()
function operation(){
inquirer.prompt([{
type: "list",
name: "action",
message: "What would you like to do?",
choices: [
'Create account',
'Check your balance',
'Deposit',
'Withdraw',
'Exit',
],
},
])
.then((answer) => {
const action = answer['action']
if(action === 'Create account'){
buildAccount()
}
console.log(action)
})
.catch((err) => console.log(err))
}
//Creating an account
function buildAccount(){
inquirer.prompt([{
type: "input",
name: "accountName",
message: "What is your name?",
},
{
type: "input",
name: "email",
message: "What is your email?",
},
{
type: "input",
name: "password",
message: "What is your password?",
},
{
type: "input",
name: "balance",
message: "What is your balance?",
}
])
.then((answer) => {
const accountName = answer['accountName']
const email = answer['email']
console.log(chalk.bgGreen.white('Thanks for choosing us !'))
console.log(chalk.green('Define your account details'))
console.log(chalk.green(`Name: ${accountName}`))
console.log(chalk.green(`Email: ${email}`))
console.log(chalk.green('Account created successfully'))
console.log(chalk.green('Thanks for choosing us !'))
if(fs.existsSync('./account.json')){
console.log(chalk.green('Account already exists'))
}else{
fs.writeFileSync('./account.json', JSON.stringify(answer))
}
fs.writeFileSync(`accounts/${accountName}.json`, '{"balance": 0}', function(err){console.log(err)}, JSON.stringify(answer))
}).catch((err) => console.log(err))
}