-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
125 lines (120 loc) · 4.2 KB
/
function.js
File metadata and controls
125 lines (120 loc) · 4.2 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
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
// Interview object array to store all the required data
var interview = [{"question": "Question 1","rating": 0, "comment": "No Comment"},
{"question": "Question 2","rating": 0, "comment": "No Comment"},
{"question": "Question 3","rating": 0, "comment": "No Comment"},
{"question": "Question 4","rating": 0, "comment": "No Comment"},
{"question": "Question 5","rating": 0, "comment": "No Comment"}
];
console.log(interview.length);
let q = 0;
document.getElementById("question").innerHTML = interview[q].question;
document.getElementById("prev").style.visibility = "hidden";
// shows the next question on clicking the '>' button
showNextQuestion = () => {
if(q < interview.length-2)
{
q++;
document.getElementById("question").innerHTML = interview[q].question;
document.getElementById("prev").style.visibility = "visible";
console.log(interview);
}
else if(q == interview.length-2)
{
q++;
document.getElementById("question").innerHTML = interview[q].question;
document.getElementById("save").innerHTML = "Save & Finish";
document.getElementById("next").style.visibility = "hidden";
}
// Last question handling
else if(q == interview.length-1)
{
alert("This is the last question");
}
}
// shows the previous question on clicking the '<' button
showPrevQuestion = () => {
if(q == interview.length-1)
{
document.getElementById("next").style.visibility = "visible";
document.getElementById("save").innerHTML = "Save";
document.getElementById("next").innerHTML = ">";
q--;
document.getElementById("question").innerHTML = interview[q].question;
}
else if(q > 0)
{
q--;
document.getElementById("question").innerHTML = interview[q].question;
if(q == 0)
document.getElementById("prev").style.visibility = "hidden";
}
// First question handling
else if(q == 0)
{
alert("Can't go back further");
}
}
// To store the rating in a temporary variable before saving it
var rating = 0;
addRating = (r) => {
rating = r
console.log(interview[q].rating);
}
// Saving the comment and rating into the interview object for the specific question
saveResponse = () =>{
if(q < interview.length-2)
{
interview[q].comment = document.getElementById("comment").value;
document.getElementById("prev").style.visibility = "visible";
document.getElementById("comment").value = "";
interview[q].rating = rating;
rating = 0;
q++;
document.getElementById("question").innerHTML = interview[q].question;
console.log(interview);
}
else if(q == interview.length-2)
{
interview[q].comment = document.getElementById("comment").value;
document.getElementById("comment").value = "";
interview[q].rating = rating;
document.getElementById("next").style.visibility = "hidden";
rating = 0;
q++;
document.getElementById("question").innerHTML = interview[q].question;
document.getElementById("save").innerHTML = "Save & Finish";
console.log(interview);
}
else if(q == interview.length-1)
{
var flag = 0;
if(interview[q].rating == 0)
{
interview[q].comment = document.getElementById("comment").value;
interview[q].rating = rating;
rating = 0;
}
var missed = [];
// Running a check to make sure all questions are answered
for(var i = 0; i < interview.length; i++)
{
if(interview[i].rating == 0)
{
missed.push(i+1);
flag = -1;
}
}
if(flag == -1)
{
console.log(missed);
alert("You have missed questions: " + missed);
}
// Saving the object in localStorage and directing to the Results page
else if(flag == 0)
{
var interviewJSON = JSON.stringify(interview);
localStorage.setItem('questions',interviewJSON);
location.href = "InterviewResults.html";
}
}
}