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
2634var LW = new BoxOfQuestions ( new LWdb ( 'learnWords' ) ) ;
2735
2836if ( LW . db . numberOfWords ( ) == 0 ) { LW . db . loadWords ( wordlist ) } ;
2937
3038
39+ // clear console
3140console . log ( '\x1Bc' ) ;
3241
42+
43+ // write title
3344console . log ( 'LearnWords2 demo' ) ;
3445console . 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
4151var 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
4466var rl = readline . createInterface ( {
@@ -47,7 +69,6 @@ var rl = readline.createInterface({
4769} ) ;
4870
4971
50-
5172rl . 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 ( ) } ;
5980rl . 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