-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg2_code.js
More file actions
49 lines (40 loc) · 1.47 KB
/
Copy pathpg2_code.js
File metadata and controls
49 lines (40 loc) · 1.47 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
btn = document.querySelector('#btn');
ques1 = document.querySelectorAll('input[name = "question1"]');
ques2 = document.querySelectorAll('input[name = "question2"]');
ques3 = document.querySelectorAll('input[name = "question3"]');
ques4 = document.querySelectorAll('input[name = "question4"]');
ques5 = document.querySelectorAll('input[name = "question5"]');
ques6 = document.querySelectorAll('input[name = "question6"]');
ques7 = document.querySelectorAll('input[name = "question7"]');
ques8 = document.querySelectorAll('input[name = "question8"]');
ques9 = document.querySelectorAll('input[name = "question9"]');
ques10 = document.querySelectorAll('input[name = "question10"]');
const qn = [ques1,ques2,ques3,ques4,ques5,ques6,ques7,ques8,ques9,ques10]; //radiobutton array
const opt = [1,4,10];
const pess = [3,7,9];
let o_val = 0, p_val = 0;
function execute()
{
for(let i = 0 ; i < 10; i++)
{
for(const r of qn[i])
{
if(r.checked)
{
let a = parseInt(r.value);
if( opt.includes((i+1)))
{
o_val += a;
}
else if( pess.includes((i+1) ))
{
p_val += a;
}
}
}
}
const opScore = o_val - p_val;
sessionStorage.setItem("opScore",opScore);
console.log(opScore);
}
btn.onclick = execute;