-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
98 lines (83 loc) · 2.73 KB
/
script.js
File metadata and controls
98 lines (83 loc) · 2.73 KB
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
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev, index) {
ev.dataTransfer.setData("text", ev.target.id);
document.getElementById('drop'+index).setAttribute('ondragover', 'allowDrop(event)');
}
function drop(ev, index) {
createAnother(index);
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
console.log(document.getElementById(data))
ev.target.appendChild(document.getElementById(data));
}
function createAnother(index){
var img = document.createElement("IMG");
if(index == "1") {
img.src = "image/hundred.svg";
img.setAttribute('alt', 'Hundred');
img.setAttribute('draggable', 'true');
img.setAttribute('ondragstart', "drag(event, '1')");
img.setAttribute('id', "drag" + (Math.floor(Math.random()*1000)+1).toString());
}
else if(index == "2") {
img.src = "image/ten.svg";
img.setAttribute('alt', 'Ten');
img.setAttribute('draggable', 'true');
img.setAttribute('ondragstart', "drag(event, '2')");
img.setAttribute('id', "drag" + (Math.floor(Math.random()*1000)+1).toString());
}
else if(index == "3") {
img.src = "image/one.svg";
img.setAttribute('alt', 'One');
img.setAttribute('draggable', 'true');
img.setAttribute('ondragstart', "drag(event, '3')");
img.setAttribute('class', "big");
img.setAttribute('id', "drag" + (Math.floor(Math.random()*1000)+1).toString());
}
else {return;}
document.getElementById('dragCont'+index).appendChild(img);
return;
}
function resetBlocks(){
var list = [document.getElementById('drop1'), document.getElementById('drop2'), document.getElementById('drop3')];
var i, length;
length = list.length;
for(i = 0; i < length; i++){
while(list[i].hasChildNodes()){
list[i].removeChild(list[i].firstChild);
}
}
}
var answer = document.getElementsByClassName('ans');
var alength = answer.length;
var question = document.getElementsByClassName('qsn');
var point = 0;
function tryAgain(){
var i;
for(i = 0; i < alength; i++){
answer[i].value = "";
}
point = 0;
resetBlocks();
}
var result = document.getElementById('result');
var score = document.getElementById('score');
function submit(){
var i;
for(i = 0; i < alength; i++){
if(eval(question[i].innerText) == answer[i].value){
point++;
}
}
result.style.opacity = 1;
result.style.zIndex = 2;
score.innerText = point;
}
function back(){
result.style.opacity = 0;
result.style.zIndex = -10;
score.innerText = point;
point = 0;
}