-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
132 lines (123 loc) · 3.55 KB
/
script.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
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
$(document).ready(function(){
i=0;
correct=0;
//Array of Color Objects
colorPrompts = [
green = {
colorBoxColor: "green",
hint: "red light, ___ light (means go when driving)"
},
lemonchiffon = {
colorBoxColor: "lemonchiffon",
hint: "citrus fruit + fabric"
},
burlywood = {
colorBoxColor:"burlywood",
hint:"Rhymes with Twirly Hood"
},
salmon = {
colorBoxColor:"salmon",
hint:"Like the fish"
},
tomato = {
colorBoxColor:"tomato",
hint:"often used to make pasta sauce"
},
thistle = {
colorBoxColor:"thistle",
hint:"___ and Thyme"
},
lawngreen = {
colorBoxColor:"lawngreen",
hint:"front ___ + color"
},
dodgerblue = {
colorBoxColor:"dodgerblue",
hint:"LA baseball team + color"
},
ghostwhite = {
colorBoxColor:"ghostwhite",
hint:"pale as a ghost"
},
gainsboro = {
colorBoxColor:"gainsboro",
hint:"gainsboro"
}
];
//start
$("#colorBox").css("background", colorPrompts[i].colorBoxColor)
$(".hintDisplay").html("<p>Hint: " + colorPrompts[i].hint + "</p>")
console.log(colorPrompts[i]);
//iterate through array
function next(i){
if (i < colorPrompts.length){
$("#colorBox").css("background", colorPrompts[i].colorBoxColor);
$(".hintDisplay").html("<p>Hint: " + colorPrompts[i].hint + "</p>");
}
//when one gets to the end of the Quiz
if (i >= colorPrompts.length){
$("#colorBox").html("<p>You have reached the end of the Quiz! You got " + correct + " of " + colorPrompts.length + " correct.</p>");
$("#colorBox").css("background", "black");
$("#colorBox").css("border", "3px solid yellow");
}
};
//Length of Question Array for Number of Questions
$("#totalQuestions").append(" of " + colorPrompts.length);
//check answer on submit
$(".submit").on("click", function (){
if
((($(".answer").val()).toLowerCase()) === (colorPrompts[i].colorBoxColor))
{console.log(colorPrompts[i].colorBoxColor);
i++;
next(i);
$(".hintDisplay").hide();
correct++;
$("#answeredQuestions").html("<h4>Correct: </h4>" + correct);
$(".answer").val("");
$(".helpDisplay").html("");
}
else
{console.log("incorrect, try the Hint!");
$(".helpDisplay").html("<p>Incorrect :( try again, remember no spaces and use the hint.</p>");
}
});
// on enter
$(".answer").keypress(function(e) { if (e.which == 13) {
if
((($(".answer").val()).toLowerCase()) === (colorPrompts[i].colorBoxColor))
{console.log(colorPrompts[i].colorBoxColor);
i++;
next(i);
$(".hintDisplay").hide();
correct++;
$("#answeredQuestions").html("<h4>Correct: </h4>" + correct);
$(".answer").val("");
$(".helpDisplay").html("");
}
else
{console.log("incorrect, try the Hint!");
$(".helpDisplay").html("<p>Incorrect :( try again, remember no spaces and use the hint.</p>");
}
}});
//Display Hint when Hint Button Clicked
$(".hintButton").on("click", function(){
$(".hintDisplay").show();
});
//Skip button
$(".skip").on("click", function(){
i++;
next(i);
$(".hintDisplay").hide();
$(".answer").val("");
$(".helpDisplay").html("");
});
//restart
$(".restart").on("click", function (){
i=0;
correct=0;
$("#colorBox").css("background", colorPrompts[i].colorBoxColor)
$(".hintDisplay").html("<p>Hint: " + colorPrompts[i].hint + "</p>")
$("#answeredQuestions").html("<h4>Correct: </h4>" + correct);
console.log(colorPrompts[i]);
});
});