-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
147 lines (100 loc) · 3.48 KB
/
form.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//Main code for question/answer verification from: https://codepen.io/meloffbird/pen/RrMeeZ
// Other code written with help from StackOverflow users:
// For timed scroll: https://stackoverflow.com/questions/50044713/slow-transition-to-same-page-anchor-with-window-location/50044854#50044854
// For border animation: https://stackoverflow.com/questions/9774134/jquery-animate-border-bottom-width
//To redirect to new page: https://stackoverflow.com/questions/4744751/how-do-i-redirect-with-javascript
// To unlock sections: https://stackoverflow.com/questions/44382153/how-to-make-div-appear-on-button-click-using-javascript
var answer = document.getElementById('guess-input').name;
var a = document.getElementById('lockChap2');
var answer2 = document.getElementById('guess-input2').name;
var answer3 = document.getElementById('guess-input3').name;
// THIRD QUESTION START
function guessAnswer() {
$("button.guess-submit").click(function (event) {
var guess = $('#guess-input').val();
guess = guess.toLowerCase();
if (guess == answer) {
a.href = "chapter2.html";
window.location = "chapter2.html";
} else {
$('#wrong3').show().fadeOut(1000);
$("#guess-input").animate({
"border-color": "#b22222"
}).animate({
"border-color": "#FEF0DC"
});
}
});
}
function enterSubmit() {
$("#guess-input").keyup(function (event) {
if (event.keyCode == 13) {
$("#guess-submit").click();
}
});
guessAnswer();
}
enterSubmit();
// THIRD QUESTION END
// SECOND QUESTION START
function guessAnswer2() {
$("button.guess-submit2").click(function (event) {
var guess2 = $('#guess-input2').val();
guess2 = guess2.toLowerCase();
if (guess2 == answer2) {
document.getElementById('sign-in').style.display = "block";
// window.location = "#sign-in";
$('html, body').animate({
scrollTop: $("#sign-in").offset().top
}, 2000);
} else {
$('#wrong2').show().fadeOut(1000);
$("#guess-input2").animate({
"border-color": "#b22222"
}).animate({
"border-color": "#FEF0DC"
});
}
});
}
function enterSubmit2() {
$("#guess-input2").keyup(function (event) {
if (event.keyCode == 13) {
$("#guess-submit2").click();
}
});
guessAnswer2();
}
enterSubmit2();
// SECOND QUESTION END
// FIRST QUESTION START
function guessAnswer3() {
$("button.guess-submit3").click(function (event) {
var guess3 = $('#guess-input3').val();
guess3 = guess3.toLowerCase();
if (guess3 == answer3) {
document.getElementById('sign-in2').style.display = "block";
//window.location = "#sign-in2";
$('html, body').animate({
scrollTop: $("#sign-in2").offset().top
}, 2000);
} else {
$('#wrong').show().fadeOut(1000);
$("#guess-input3").animate({
"border-color": "#b22222"
}).animate({
"border-color": "#FEF0DC"
});
}
});
}
function enterSubmit3() {
$("#guess-input3").keyup(function (event) {
if (event.keyCode == 13) {
$("#guess-submit3").click();
}
});
guessAnswer3();
}
enterSubmit3();
// FIRST QUESTION END