-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
180 lines (161 loc) · 13.7 KB
/
script.js
File metadata and controls
180 lines (161 loc) · 13.7 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
mydata = [{"question":{"harc":"What is the correct JavaScript syntax to change the content of the HTML element below? < p id=demo >This is a demonstration.< /p>","answers":{"true":"document.getElementById(demo).innerHTML = Hello World!;","two":"#demo.innerHTML = Hello World!;","three":"document.getElementByName(p).innerHTML = Hello World!;","for":"document.getElement(p).innerHTML = Hello World!;"}}}, {"question":{"harc":"What is the correct JavaScript syntax for opening a new window called w2 ?","answers":{"true":"w2=window.open(http://www.w3schools.com);","two":"w2=window.new(http://www.w3schools.com);","three":"w2= window.location(http://www.w3schools.com);","for":"w2= window.redirect(http://www.w3schools.com);"}}}, {"question":{"harc":"How do you round the number 7.25, to the nearest integer?","answers":{"true":"Math.round(7.25)","two":"rnd(7.25)","three":"Math.rnd(7.25)","for":"round(7.25)"}}}, {"question":{"harc":"What is the correct way to write a JavaScript array?","answers":{"true":"var colors = [1, 2, 3]","two":"var colors = (1:red, 2:green, 3:blue)","three":"var colors = red, green, blue","for":"var colors = 1 = (red), 2 = (green), 3 = (blue)"}}}, {"question":{"harc":"The external JavaScript file must contain the < script > tag","answers":{"true":"True","two":"False","three":"I dont now","for":"Right response is not"}}}, {"question":{"harc":"How do you write `Hello World` in an alert box?","answers":{"true":"alert(`Hello World`);","two":"msgBox(`Hello World`);","three":"alertBox(`Hello World`);","for":"msg(`Hello World`);"}}}, {"question":{"harc":"How do you create a function in JavaScript?","answers":{"true":"function myFunction()","two":"function:myFunction()","three":"function = myFunction()","for":"Function = new()"}}}, {"question":{"harc":"How do you call a function named `myFunction`?","answers":{"true":"myFunction()","two":"call myFunction()","three":"call function myFunction()","for":"try myFunction()"}}}, {"question":{"harc":"How to write an IF statement in JavaScript?","answers":{"true":"if (i == 5)","two":"if i = 5 then","three":"if i == 5 then","for":"if i = 5"}}}, {"question":{"harc":"How to write an IF statement for executing some code if `i` is NOT equal to 5?","answers":{"true":"if (i != 5)","two":"if (i <> 5)","three":"if i <> 5","for":"if i =! 5 then"}}}, {"question":{"harc":"How can you detect the clients browser name?","answers":{"true":"browser.name","two":"client.navName","three":"navigator.appName","for":"clone.NodeName"}}}, {"question":{"harc":"How can you add a comment in a JavaScript?","answers":{"true":" //This is a comment ","two":"`This is a comment","three":"< !--This is a comment-- >","for":"There is not currect answer"}}}, {"question":{"harc":" Which event occurs when the user clicks on an HTML element?","answers":{"true":" onclick","two":"onmouseover","three":"onchange","for":"onmouseclick"}}}, {"question":{"harc":"Which operator is used to assign a value to a variable?","answers":{"true":" =","two":"+","three":"-","for":"/"}}}, {"question":{"harc":"What will be return value?(0.457).toFixed(2) === 0.45","answers":{"true":"false","two":"Error in the code","three":"undefined","for":"true"}}}, {"question":{"harc":"What the following code return? `null == undefined`","answers":{"true":"false","two":"Error in the code","three":"undefined","for":"true"}}}, {"question":{"harc":"What will be the return value of the following code?‘abc’ === new String(‘abc’)","answers":{"true":"false","two":"Error in the code","three":"undefined","for":"true"}}}, {"question":{"harc":"What will be the output of the following code?var x = 10, y = 20;alert(x++-++y+x++);","answers":{"true":"0","two":"5","three":"-5","for":"-10"}}}, {"question":{"harc":"What does the following code will return?~~(-5.5)","answers":{"true":"-5","two":"5","three":"Error in the code","for":"0"}}}, {"question":{"harc":"What will be the return value of the following code? `(function(a){delete a;return a;})(1)`;","answers":{"true":"1","two":"null","three":"Error in the code","for":"undefined"}}}, {"question":{"harc":"What will be the return value of the following code? `parseInt( null, 24 ) === 23;`","answers":{"true":"true","two":"null","three":"Error in the code","for":"undefined"}}}, {"question":{"harc":"What will be the output of the following code?alert([1,2] + [3,4]);","answers":{"true":"1,23,4","two":"154","three":"1,5,4","for":"undefined"}}}, {"question":{"harc":"What will be the return value of the following code? `!function () {}();`","answers":{"true":"true","two":"undefined","three":"false","for":"Error in the code."}}}, {"question":{"harc":"What will be the output, when we call the following function? `function my_func(str){var pattern = /\d/;var output = str.match(pattern);alert(output);}my_func(‘w3resource.com’);`","answers":{"true":"3","two":"w,3,r,e,s,o,u,r,c,e,c,o,m","three":"w,3,r,e,s,o,u,r,c,e,.,c,o,m","for":"w,r,e,s,o,u,r,c,e,c,o,m"}}}, {"question":{"harc":"What will be the return value of the following code? `(1.22e-10).toFixed(2)`","answers":{"true":"0.00","two":"122000000000000000000.00","three":"0","for":"0.0"}}}, {"question":{"harc":"What will be the output?`alert(({ valueOf:function() { return 2; } }) == 2);`","answers":{"true":"true","two":"false","three":"Error in the code","for":"undefined"}}}, {"question":{"harc":"What will be the output of the following code?`alert(‘121212’.split(‘2’).join(‘2’));`","answers":{"true":"121212","two":"222222","three":"111111","for":"212121"}}}, {"question":{"harc":"What will be the output? `alert(({ valueOf:function() { return 1; } }) === true);`","answers":{"true":"true","two":"Error in the code","three":"false","for":"undefined"}}}, {"question":{"harc":"What will be the output of the following code? `alert(typeof typeof(typeof(undefined)));`","answers":{"true":"string","two":"Error in the code","three":"null","for":"undefined"}}}, {"question":{"harc":"What does the following code return? “,,,,” == Array(4)","answers":{"true":"false","two":"Error in the code","three":"null","for":"undefined"}}}, {"question":{"harc":"Which of the following is an advantage of using JavaScript?","answers":{"true":"All of the above.","two":"Less server interaction","three":"Increased interactivity","for":"Immediate feedback to the visitors"}}}, {"question":{"harc":"Which of the following is a valid type of function javascript supports?","answers":{"true":"Both of the above.","two":"None of the above.","three":"anonymous function","for":"named function"}}}, {"question":{"harc":"Which built-in method returns the length of the string?","answers":{"true":"length()","two":"size()","three":"index()","for":"None of the above."}}}, {"question":{"harc":"Which of the following code creates an object?","answers":{"true":"var book = new Object();","two":"var book = Object();","three":"var book = new OBJECT();","for":"var book = new Book();"}}}, {"question":{"harc":"Which of the following function of Number object defines how many total digits to display of a number?","answers":{"true":"toPrecision()","two":"toExponential()","three":"toFixed()","for":"toLocaleString()"}}}, {"question":{"harc":"Which of the following function of String object executes the search for a match between a regular expression and a specified string?","answers":{"true":"search()","two":"concat()","three":"replace()","for":"match()"}}}, {"question":{"harc":"Which of the following function of String object returns the primitive value of the specified object.","answers":{"true":"valueOf()","two":"toLocaleUpperCase()","three":"toUpperCase()","for":"toString()"}}}, {"question":{"harc":"var foo = function foo() { console.log(foo === foo);} foo();","answers":{"true":"true","two":"false","three":"Error","for":"undefined"}}}, {"question":{"harc":"Number(`1`) - 1 == 0;","answers":{"true":"true","two":"false","three":"Error","for":"undefined"}}}];
//var mydata = JSON.parse(data);
var harc = document.querySelector(".question_head");
var pat1 = document.querySelector(".ans1");
var pat2 = document.querySelector(".ans2");
var pat3 = document.querySelector(".ans3");
var pat4 = document.querySelector(".ans4");
var right = document.querySelector(".right");
var procent = document.querySelector(".procent");
var spent_time = document.querySelector(".spent_time");
var spanElems = document.getElementsByTagName("span");
var responses = document.querySelector(".responses");
var a, b, c, d, arr=[], cout=1, chisht=0, sxal=0, empty_array=[];
var shuffleArray = function(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}
harc.innerHTML =(cout++) +". " + mydata[0].question.harc;
a = mydata[0].question.answers.true;
b = mydata[0].question.answers.two;
c = mydata[0].question.answers.three;
d = mydata[0].question.answers.for;
mydata.splice(mydata[0], 1);
return array;
}
mydata = shuffleArray(mydata);
function push_arr(){
arr.push(a,b,c,d);
if(arr.length> 4){
arr.splice(0,4);
}
var true_or_false = [arr[0], arr[1], arr[2],arr[3]];
var random = 0;
var temp = 0;
for(var i=0;i<true_or_false.length; i++){
random = Math.floor(Math.random()*i);
temp = true_or_false[i];
true_or_false[i] = true_or_false[random];
true_or_false[random] = temp;
}
pat1.innerHTML = true_or_false[0];
pat2.innerHTML = true_or_false[1];
pat3.innerHTML = true_or_false[2];
pat4.innerHTML = true_or_false[3];
}
push_arr();
function checkboxes(){
var h2 = document.createElement("h4");
var sp = document.createElement("p");
sp.className = "white_text";
var sp2 = document.createElement("p");
var inputElems = document.getElementsByTagName("input");
for (var i=0; i<inputElems.length; i++) {
if (inputElems[i].type === "radio" && inputElems[i].checked === true){
next.disabled = true;
function test(){
h2.innerHTML = "<h2>"+ harc.innerHTML +"</h2>";
responses.appendChild(h2);
responses.appendChild(sp);
responses.appendChild(sp2);
if(spanElems[i].innerHTML == a){
chisht++;
sp.innerHTML = spanElems[i].innerHTML;
sp2.innerHTML = "Your answer is Fine";
sp2.style.color= "green";
empty_array.push(sp, sp2);
}
else{
sxal++;
sp.innerHTML = spanElems[i].innerHTML;
sp2.innerHTML = "Your answer is Wrong";
sp2.style.color = "red";
empty_array.push(sp, sp2);
}
}
test();
}
}
}
var time = 0, minute=0;
var block_saw = document.querySelector(".time");
block_saw.innerHTML = 0 + ":" + "00";
var setTime = setInterval(function(){ interTime()}, 1000);
function interTime(){
time++;
if(time< 10){
block_saw.innerHTML = minute+ ":0"+time;
}
else if(time > 55 && time < 59){
block_saw.classList = "pulse";
block_saw.innerHTML = minute+ ":"+time;
}
else if(time > 59){
time = 0;
block_saw.removeAttribute("class", "pulse");
block_saw.classList = "time";
minute++;
block_saw.innerHTML = minute+ ":0"+time;
}
else{
block_saw.innerHTML = minute+ ":" +time;
}
}
function response(){
if(mydata.length == 14){
mydata.splice(0,14);
clearInterval(setTime);
spent_time.innerHTML ="Your spent Time " + block_saw.innerHTML;
var dis = document.myForm.answer;
for(var i =0; i< dis.length; i++){
dis[i].disabled = true;
}
document.querySelector(".response").style.display = "block";
right.innerHTML = chisht + " of " + 25;
procent.innerHTML = "<b>" + Math.round((chisht * 100)/25) + "%" + "</b>";
document.querySelector(".want").style.transition = "all 1.4s";
document.querySelector(".want").style.top = 25+"%";
}
}
document.querySelector(".yes").onclick = function(){
responses.style.display = "block";
document.querySelector(".want").style.display="none";
}
document.querySelector(".no").onclick = function (){
window.location.reload();
}
var next = document.querySelector(".next");
next.disabled = true;
next.style.backgroundColor = "gray";
var dis = document.myForm.answer;
for(var i =0; i< dis.length; i++){
dis[i].onclick = function(){
next.disabled = false;
next.style.backgroundColor = "#FF6500";
}
}
var plus_progres = 0;
var progres = document.querySelector(".progres_bar");
progres.style.width = 0 + "%";
next.onclick = function(){
plus_progres+=4;
progres.style.width = plus_progres + "%";
var dis = document.myForm.answer;
for(var i =0; i< dis.length; i++){
dis[i].disabled = true;
next.style.backgroundColor = "gray";
}
checkboxes(); document.querySelector("input[type=radio]:checked").checked = false;
setTimeout(function(){
for(var i =0; i< dis.length; i++){
dis[i].disabled = false;
}
response();
shuffleArray(mydata);
push_arr();
}, 1500);
}