-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserInterface.js
More file actions
84 lines (70 loc) · 2.06 KB
/
userInterface.js
File metadata and controls
84 lines (70 loc) · 2.06 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
77
78
79
80
81
const readline = require('readline-sync');
function performOneAction(){
console.log("Welcome to the Support bank");
let year;
const goodYears = ['2012','2013','2014','2015'];
do {
year = userInput("Which year would you like to see?")
} while (goodYears.includes(year));
let file = year2file(year);
const goodActions = ['1','2','3','4'];
let actionRequired
do {
actionRequired = userInput(`What Function would you like?
(1): LIST ALL names with their credit
(2): LIST one single account and all transactions associated with it
(3): IMPORT FILE from disk
(4): END`);
} while (goodActions.includes(actionRequired));
return file, actionRequired
}
function year2file(year){
let file;
switch (year) {
case 2012:
file = 'Transactions2012.xml';
break;
case 2013:
file = 'Transactions2013.json';
break;
case 2014:
file = 'Transactions2014.csv';
break;
case 2015:
file = 'DodgyTransactions2015.csv';
break;
default: //optional but good practise
console.log("Oops");
break;
}
return file
}
function userInterface(){
performOneAction()
}
function getFile(){
let year;
const goodYears = ['2012','2013','2014','2015'];
year = userInput()
const goodActions = ['1','2','3','4'];
let actionRequired
do {
actionRequired = userInput(`What Function would you like?
(1): LIST ALL names with their credit
(2): LIST one single account and all transactions associated with it
(3): IMPORT FILE from disk
(4): END`);
} while (goodActions.includes(actionRequired));
return file, actionRequired
}
function userInput(prompt, allowed= []){
let response;
if (!(allowed === [])){
do {
response = userInput(prompt)
} while (allowed.includes(response));
} else {
response = userInput(prompt)
}
return response
}