-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (65 loc) · 1.32 KB
/
index.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
var tiers = [];
var all_items = [];
var results = [];
var set = 0;
var index = 0;
function start() {
results.push(0);
next();
}
function yes() {
results[set]++;
next();
}
function no() {
next();
}
function next() {
if (set < all_items.length && index < all_items[set].length) {
$("h1").html(all_items[set][index]);
index++;
} else if (set < all_items.length) {
index = 0;
set++;
results.push(0);
next();
} else {
end();
}
}
function end() {
var total = 0;
var last_tier = 0;
$.each(tiers, function(i, tier) {
tier = parseInt(tier);
var max = all_items[i].length;
var percent = results[i] / max;
var words = Math.round(percent * (tier - last_tier));
total += words;
last_tier = tier;
});
$("h1").html(total + " слов");
console.log(results);
}
$(document).ready(function() {
$("#yes").bind('click', yes);
$("#no").bind('click', no);
$.ajax({
url: '/list.php',
type: 'GET',
dataType: 'json',
success: function(data, status, xhr) {
var index = 0;
$.each(data, function(key, value) {
tiers.push(key);
all_items.push(new Array());
$.each(value, function(i, word) {
all_items[index].push(word.words);
});
index++;
});
start();
console.log(data);
}
});
});