Skip to content

Commit 4f92d81

Browse files
committed
comment update
1 parent 1f64799 commit 4f92d81

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

scripts/demo.js

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
"use strict";
2-
var LWdb = require('../src/LWdb');
3-
var BoxOfQuestions = require('../src/BoxOfQuestions');
4-
var wordlist = require('../data/wordlist-en-ge.js');
5-
6-
var readline = require('readline');
7-
81
// ----------------------------------------------
92
// LearnWords2 API usage
103
//
@@ -19,26 +12,55 @@ var readline = require('readline');
1912
// LW.moveQuestionForward()
2013
// LW.moveQuestionBackwards()
2114
//
15+
//
16+
//
17+
// Asks one word and then terminates
2218
// ----------------------------------------------
2319

20+
"use strict";
21+
var readline = require('readline');
22+
23+
24+
var LWdb = require('../src/LWdb');
25+
var BoxOfQuestions = require('../src/BoxOfQuestions');
26+
27+
28+
var wordlist = require('../data/wordlist-en-ge.js');
29+
30+
2431

32+
// set up the LW (learnwords) object
2533

2634
var LW = new BoxOfQuestions(new LWdb('learnWords'));
2735

2836
if (LW.db.numberOfWords() == 0) {LW.db.loadWords(wordlist)};
2937

3038

39+
// clear console
3140
console.log('\x1Bc');
3241

42+
43+
// write title
3344
console.log('LearnWords2 demo');
3445
console.log('');
35-
console.log('Type the answers:');
36-
console.log('');
3746

3847

39-
// var aWord = {_id: 1, "word": "apple", "translate": "der Apfel"};
48+
49+
// get a question from the box
4050

4151
var aWord = LW.question();
52+
// gives for example
53+
// {_id: 1, "word": "apple", "translate": "der Apfel", "step": 0, "date": 0};
54+
55+
56+
57+
58+
// if we got a question ask for the translation of the word
59+
60+
if (aWord) {
61+
62+
console.log('Type the answers:');
63+
console.log('');
4264

4365

4466
var rl = readline.createInterface({
@@ -47,7 +69,6 @@ var rl = readline.createInterface({
4769
});
4870

4971

50-
5172
rl.question(aWord.word + " = ", function(answer) {
5273
answer = answer.toString().trim();
5374

@@ -57,7 +78,11 @@ rl.question(aWord.word + " = ", function(answer) {
5778
else {console.log('the correct answer is:', LW.answer());
5879
LW.moveQuestionBackwards()};
5980
rl.close();
60-
61-
});
81+
})
82+
} else {console.log('As of now there are no more words to repeat.')};
6283

6384

85+
// currently only one question is asked and then the program quits.
86+
// you have to restart the program to get the next question.
87+
//
88+
// the db entries are in the 'scratch' subdirectory

0 commit comments

Comments
 (0)