-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestionMaker.js
71 lines (61 loc) · 2.1 KB
/
questionMaker.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
const operators = [ '>', '<', '==', '!=', '>=', '<=']
const comparors = ['||', '&&']
const booleans = ['false', 'true']
const difficulties = ['easy', 'medium', 'hard']
Array.prototype.random = function () {
return this[Math.floor(Math.random() * this.length)]
}
function randomNumber(){
return Math.floor(Math.random() * 100)
}
class questionMaker {
static base(){
return `${randomNumber()} ${operators.random()} ${randomNumber()}`
}
static hardBase(){
return `${booleans.random()} ${comparors.random()} ${booleans.random()}`
}
static easyQuestion(){
return `${questionMaker.base()} ${comparors.random()} ${questionMaker.base()}`
}
static medQuestion(){
return `${questionMaker.easyQuestion()} ${comparors.random()} ${questionMaker.easyQuestion()}`
}
static hardQuestion(){
if (counter % 2 == 0) {
return `((${questionMaker.hardBase()}) ${comparors.random()} ${booleans.random()}) ${comparors.random()} ((${questionMaker.hardBase()}) ${comparors.random()} ${booleans.random()})`
}
else if (counter % 3 == 0) {
return `((${questionMaker.hardBase()}) ${comparors.random()} ${booleans.random()}) ${comparors.random()} (!(${questionMaker.hardBase()}) ${comparors.random()} ${booleans.random()})`
}
else {
return `(!(${questionMaker.hardBase()}) ${comparors.random()} ${booleans.random()}) ${comparors.random()} ((${questionMaker.hardBase()}) ${comparors.random()} ${booleans.random()})`
}
}
static randomQuestion(){
let randomDifficulty = difficulties.random()
if (randomDifficulty == 'easy'){
return questionMaker.easyQuestion()
}
else if (randomDifficulty == 'medium'){
return questionMaker.medQuestion()
}
else {
return questionMaker.hardQuestion()
}
}
static createQuestion(difficulty){
if (difficulty == 'easy'){
return questionMaker.easyQuestion()
}
else if (difficulty == 'medium'){
return questionMaker.medQuestion()
}
else if (difficulty == 'hard') {
return questionMaker.hardQuestion()
}
else {
return questionMaker.randomQuestion()
}
}
}