-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearnlooly.js
73 lines (66 loc) · 2.4 KB
/
learnlooly.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
73
function MCimportstack(list, listitem){ //Makes answer
var anslist = [listitem[1]];
for(var i = 0; i < 3; i++){
//pick a random answer
var choiceFull = list[Math.floor(Math.random()*list.length)];
var choice = choiceFull[1];
/* console.log('P: '+p);
console.log(`Answer: `+a); */
while(anslist.includes(choice)){ //No Duplicates!
choiceFull = list[Math.floor(Math.random()*list.length)];
choice = choiceFull[1];
//console.log(a);
}
anslist.push(choice);
}
return [listitem[0],anslist[0],anslist[1],anslist[2],anslist[3]];
}
function getMCitems(list) {
var MClist = [];
for(var i = 0; i < list.length; i++){
var listitem = list[i];
MClist[i] = MCimportstack(list, listitem);
}
return MClist;
}
function shuffleArray(array){
for(var i = array.length - 1; i > 0; i--){
var j = Math.floor(Math.random()*(i+1));
var tempArI = array[i];
array[i] = array[j];
array[j] = tempArI;
}
return array;
}
function randomQuestion(options, details){
if(!details){
return {error: "No Specified Details", specs: details};
}
var Qid = Math.floor(Math.random() * options.length);
var Question = options[Qid];
if(details.type == 0){
var Answer = Question[1];
var Question_Only = Question[0]
var txt="<label for='W'><h1 id='q'>"+Question[0]+"</h1></label>";
txt +="<div id='WDIV'><input id='W' name='W' placeholder='Written Input'/>"
txt+="<button id='bw' style='background:"+details.color[4]+"; color:"+details.color[9]+"'onclick=\" if(document.getElementById('W').value=='"+Answer+"'){CorrectAnswer("+Qid+","+Answer+");} else{WrongAnswer("+Qid+",document.getElementById('W').value)}\">Check</button></div>"
}
else if(details.type == 1){
var Answers = [Question[1],Question[2],Question[3],Question[4]];
var QuestionTxt = Question[0];
var CorrectAns = Question[1];
var ShuffledAns = shuffleArray(Answers);
var txt="<h1 id='q'>"+QuestionTxt+"</h1>";
for(var i = 0; i<4; i++){
var AnsButtonClick = "WrongAnswer("+i+","+ShuffledAns[i]+")"
if(ShuffledAns[i] === CorrectAns){
AnsButtonClick = "CorrectAnswer("+i+","+ShuffledAns[i]+")"
}
txt+= "<button id='b"+i+"' style='background:"+details.color[i]+";color:"+details.color[(i+5)]+"'"
txt += "onclick='" + AnsButtonClick+ "'>" + ShuffledAns[i] +"</button>"
}}
else{
return {error: "Not A Valid Type", specs: details}
}
document.getElementById('body').innerHTML = txt;
}