-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
154 lines (131 loc) · 5.14 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//use inquirer npm package to prompt the user and have him/her input a choice
var inquirer = require("inquirer");
//use fs npm package to read and write to text files
var fs = require("fs");
//use request npm package to request other files
var request = require("request");
//require or call js files that contain the constructors needed to execute user choices
var basic = require("./basic.js");
var cloze = require("./cloze.js");
//prompt user to input the operation: store cards or get card info
inquirer.prompt([
{
type: "input",
name: "operation",
message: "Hi There, To store a flashcard type store, to retrieve flashcard information type get"
}
]).then(function(answer){
//if user chooses to store info call the function for that
if (answer.operation === "store") {
storeOperation();
}
//if user chooses to retrieve info call the function for that
if (answer.operation === "get") {
readOperation();
}
});
var storeOperation= function(){
//prompt user to input the type of flashcards he wants to store
inquirer.prompt([
{
type: "input",
name: "basicOrCloze",
message: "To store a basic flashcard type basic,to store a cloze flashcard type cloze"
}
]).then(function(answer){
//if user chooses basic run the funtion that stores basic flashcards
if (answer.basicOrCloze === "basic") {
storeBasic();
}
//if user chooses cloze run the funtion that stores cloze flashcards
if (answer.basicOrCloze === "cloze") {
storeCloze();
}
});
}
//prompt user to input the type of flashcards he wants to read
var readOperation= function(){
inquirer.prompt([
{
type: "input",
name: "basicOrCloze",
message: "To retrieve basic flashcards type basic,to retrieve cloze flashcards type cloze"
}
]).then(function(answer){
//if user chooses basic run the funtion that reads basic flashcards
if (answer.basicOrCloze === "basic") {
readBasic();
//console.log("yes1");
}
//if user chooses cloze run the funtion that reads cloze flashcards
if (answer.basicOrCloze === "cloze") {
readCloze();
}
});
}
// function to get info needed for storing basic flashcards
var storeBasic= function(){
inquirer.prompt([
//prompt user to input front text for basic flashcards
{
type: "input",
name: "front",
message: "Enter front text between quotations"
},
//prompt user to input back text for basic flashcards
{
type: "input",
name: "back",
message: "Enter back text between quotations"
}
]).then(function(answer){
// pass values to a function that calls constructors from basic.js file
basicFlashCard(answer.front,answer.back);
});
}
// function to get info needed for storing cloze flashcards
var storeCloze= function(){
inquirer.prompt([
//prompt user to input partial text for cloze flashcards
{
type: "input",
name: "text",
message: "Enter partial text between quotations"
},
//prompt user to input the deleted text for cloze flashcards
{
type: "input",
name: "deletion",
message: "Enter deletion between quotations"
}
]).then(function(answer){
// pass values to a function that calls constructors from cloze.js file
clozeFlashCard(answer.text,answer.deletion);
});
}
//function that passes values to constructor in basic.js file
var basicFlashCard = function(front,back){
var basicCard = new basic(front,back);
basicCard.storeCard(front,back);
console.log('you logged this to the text file: ' +"'"+basicCard.front+"'" + "for the front side "+"and" + "'" +basicCard.back + "'"+"for the back side" );
}
//function that passes values to constructor in cloze.js file
var clozeFlashCard = function(text,deletion){
var clozeCard = new cloze(text,deletion);
clozeCard.fullText(text,deletion);
clozeCard.partialText(text);
clozeCard.deletion(deletion);
console.log('the full text you logged to the text file is: '+ text + " " +deletion);
}
//function that reads text file values using constructor in basic.js file
var readBasic = function(){
fs.readFile("log.txt", "utf8", function(error, data) {
console.log("these are all stored basic flashcards: " +data);
});
}
//function that reads text file values using constructor in cloze.js file
var readCloze = function(){
fs.readFile("fulllog.txt", "utf8", function(error, data) {
console.log("these are all stored cloze flashcards: "+data);
});
}