-
Notifications
You must be signed in to change notification settings - Fork 3
/
NumbersCardinalNominative.html
195 lines (158 loc) · 7.98 KB
/
NumbersCardinalNominative.html
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html>
<head>
<title>
LT Exercise -- Numbers Cardinal Nominative
</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/ToC.css">
<link rel="stylesheet" href="css/pageStructure.css">
<script type="text/javascript" src="js/Common.js"> </script>
<script type="text/javascript">
ButtonNext_OnPageLoad();
SetupArrayFunctions();
// All samples
var samples0_9 = '{"Numbers":[{"Number":0,"Forms":[{"Gender":"Neutral","Form":"Nulis"}]},{"Number":1,"Forms":[{"Gender":"Masculine","Form":"Vienas"},{"Gender":"Feminine","Form":"Viena"}]},{"Number":2,"Forms":[{"Gender":"Masculine","Form":"Du"},{"Gender":"Feminine","Form":"Dvi"}]},{"Number":3,"Forms":[{"Gender":"Masculine","Form":"Trys"},{"Gender":"Feminine","Form":"Trys"}]},{"Number":4,"Forms":[{"Gender":"Masculine","Form":"Keturi"},{"Gender":"Feminine","Form":"Keturios"}]},{"Number":5,"Forms":[{"Gender":"Masculine","Form":"Penki"},{"Gender":"Feminine","Form":"Penkios"}]},{"Number":6,"Forms":[{"Gender":"Masculine","Form":"Šeši"},{"Gender":"Feminine","Form":"Šešios"}]},{"Number":7,"Forms":[{"Gender":"Masculine","Form":"Septyni"},{"Gender":"Feminine","Form":"Septynios"}]},{"Number":8,"Forms":[{"Gender":"Masculine","Form":"Aštuoni"},{"Gender":"Feminine","Form":"Aštuonios"}]},{"Number":9,"Forms":[{"Gender":"Masculine","Form":"Devyni"},{"Gender":"Feminine","Form":"Devynios"}]}]}';
var samples10_19 = '{"Numbers":[{"Number":10,"Forms":[{"Gender":"Neutral","Form":"dešimt"}]},{"Number":11,"Forms":[{"Gender":"Neutral","Form":"vienuolika"}]},{"Number":12,"Forms":[{"Gender":"Neutral","Form":"dvylika"}]},{"Number":13,"Forms":[{"Gender":"Neutral","Form":"trylika"}]},{"Number":14,"Forms":[{"Gender":"Neutral","Form":"keturiolika"}]},{"Number":15,"Forms":[{"Gender":"Neutral","Form":"penkiolika"}]},{"Number":16,"Forms":[{"Gender":"Neutral","Form":"šešiolika"}]},{"Number":17,"Forms":[{"Gender":"Neutral","Form":"septyniolika"}]},{"Number":18,"Forms":[{"Gender":"Neutral","Form":"aštuoniolika"}]},{"Number":19,"Forms":[{"Gender":"Neutral","Form":"devyniolika"}]}]}';
var samples20_90 = '{"Numbers":[{"Number":20,"Forms":[{"Gender":"Neutral","Form":"dvidešimt"}]},{"Number":30,"Forms":[{"Gender":"Neutral","Form":"trisdešimt"}]},{"Number":40,"Forms":[{"Gender":"Neutral","Form":"keturiasdešimt"}]},{"Number":50,"Forms":[{"Gender":"Neutral","Form":"penkiasdešimt"}]},{"Number":60,"Forms":[{"Gender":"Neutral","Form":"šešiasdešimt"}]},{"Number":70,"Forms":[{"Gender":"Neutral","Form":"septyniasdešimt"}]},{"Number":80,"Forms":[{"Gender":"Neutral","Form":"aštuoniasdešimt"}]},{"Number":90,"Forms":[{"Gender":"Neutral","Form":"devyniasdešimt"}]}]}';
// Sample : {"Number":1,"Forms":[{"Gender":"Masculine","Form":"Vienas"},{"Gender":"Feminine","Form":"Viena"}]}
// Result : [{Number, Gender, Text}, {Number, Gender, Text}]
function mapNumberToExercisesArray(sample){
var number = sample.Number;
var result = sample.Forms.map(
(form) => ({
Number:number,
Gender:form.Gender,
Text:form.Form
})
);
return result;
}
// Prepare basic exercies
var exercises0_9 = JSON.parse(samples0_9).Numbers
.reduce((totalValue, currentNumber) => [...totalValue, ...mapNumberToExercisesArray(currentNumber)], []);
var exercises10_19 = JSON.parse(samples10_19).Numbers
.reduce((totalValue, currentNumber) => [...totalValue, ...mapNumberToExercisesArray(currentNumber)], []);
var exercises20_90 = JSON.parse(samples20_90).Numbers
.reduce((totalValue, currentNumber) => [...totalValue, ...mapNumberToExercisesArray(currentNumber)], []);
// Build a set of exercises including all numbers from 0 till 99
var exercises0_99 = [];
exercises0_99 = [...exercises0_99, ...exercises0_9];
exercises0_99 = [...exercises0_99, ...exercises10_19];
for(i=0; i<exercises20_90.length; i++){
for(j=0; j<exercises0_9.length; j++){
var mostNumber = exercises20_90[i];
var leastNumber = exercises0_9[j];
var number = mostNumber.Number + leastNumber.Number;
var gender = leastNumber.Gender;
var text = mostNumber.Text; ;
if(leastNumber.Number != 0){text += ' ' + leastNumber.Text;}
exercises0_99.push({
Number: number,
Gender: gender,
Text: text
});
}
}
// Setup levels manually
exercises0_9 = exercises0_9.map(exercise => ({...exercise, Level:1}));
exercises10_19 = exercises10_19.map(exercise => ({...exercise, Level:2}));
exercises20_90 = exercises20_90.map(exercise => ({...exercise, Level:3}));
exercises0_99 = exercises0_99.map(exercise => ({...exercise, Level:4}));
// Build leveller
var leveller = CreateLevelledArray(
[...exercises0_9, ...exercises10_19, ...exercises20_90, ...exercises0_99],
elem => elem.Level
);
var content = leveller.GetContent();
var fullButtonsElementHtml = leveller.RegenerateButtons();
// Setup first sample
var currentSample = content.random();
notification = {};
function onNextActionButtonClick(){
// Check if it's answer request or next sample request
var isAnswerRequest = false;
var button = document.getElementById('NextActionButton');
if(button.innerText == 'Check answer') {isAnswerRequest = true;}
else {isAnswerRequest = false;}
// Call the respective function based on the request type
if(isAnswerRequest){
onAnswerRequest();
}
else { onNextSampleRequest(); }
}
function onAnswerRequest(){
// Show answer
var answerDiv = document.getElementById('Answer');
answerDiv.innerHTML = currentSample.Text.toLowerCase();
// Amend button text
var button = document.getElementById('NextActionButton');
button.innerText = 'Next';
// Notification
notification.Answer = currentSample.Text;
}
function onNextSampleRequest(){
// Clean up answer
var answerDiv = document.getElementById('Answer');
answerDiv.innerHTML = '';
// Amend button text
var button = document.getElementById('NextActionButton');
button.innerText = 'Check answer';
// Setup new sample
var randomSample = content.notRepeatingRandom(currentSample);
currentSample = randomSample;
// Setup question div
var divToAmend = document.getElementById('Question');
var question = currentSample.Number.toString();
if(currentSample.Gender != "Neutral"){
question += ' '+ currentSample.Gender;
}
divToAmend.innerHTML = question.toLowerCase();
// Notification
notification.Question = question;
notification.Answer = null;
}
function OnLevelButtonClick(button){
// Setup level
leveller.SetupLevel(button.value);
// Update innerHtml for level buttons div
let newHtml = leveller.RegenerateButtons("OnLevelButtonClick");
var buttonsElement = document.getElementById("levelButtonsDiv");
buttonsElement.innerHTML = newHtml;
// Update content
content = leveller.GetContent()
.filter(elem => elem.Level == leveller.CurrentLevel);
}
</script>
</head>
<body>
<div id='pageStructure' class="pageStructure">
<div id='ToC' class='ToC'></div>
<script type="text/javascript" src="js/ToC.js"> </script>
<script> uploadToC(); </script>
<div id="exercise" class="exercise">
<div id='table' class='content'>
<div id='Question'> 5 feminine </div>
<div id='Answer'> penkios </div>
<div id='Button'>
<button id='NextActionButton'
onclick="onNextActionButtonClick()">
Next
</button>
</div>
</div>
<div id="levelButtonsDiv" class="levelButtonsDiv"> </div>
<script>
var buttonsElement = document.getElementById("levelButtonsDiv");
buttonsElement.innerHTML = leveller.RegenerateButtons("OnLevelButtonClick");
</script>
<div class="issueNotificationDiv">
<button id='notifyButton'
onclick="notify(notification.Question, notification.Answer)">
Tell about an error
</button>
</div>
</div>
</div>
</body>
</html>