-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion15.html
More file actions
127 lines (113 loc) · 3.55 KB
/
question15.html
File metadata and controls
127 lines (113 loc) · 3.55 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
<!DOCTYPE html>
<html lang="de">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Fragen</title>
<link rel="stylesheet" href="question.css"/>
</head>
<body>
<div class="switchContainer">15 / 15</div>
<div class="question-container">
<div id="question"></div>
<div id="answers">
<button class="answer"></button>
<button class="answer"></button>
<button class="answer"></button>
<button class="answer"></button>
</div>
</div>
<div class="button-container">
<button class="switch" onclick="end()">Beenden</button>
</div>
<script>
var nextButton = document.querySelector("div.button-container button");
nextButton.disabled = true;
const correctAnswerNumber = 0;
let data = JSON.parse(localStorage.getItem('formData'));
if (!data) {
data = [
{
name: 'Cookie-Selection',
description: 'denied?',
value: false
},
{
name: 'Opt-Out',
description: 'pressed?',
value: false,
},
{
name: 'Preselection',
description: 'disbaled?',
value: false,
},
{
name: 'Disguised Ads',
description: 'clickCount',
value: 0,
}
];
}
function end() {
console.log("submitting...!")
const titleKeys = Object.keys(data[0]);
const refinedData = [];
refinedData.push(titleKeys);
data.forEach(item => {
refinedData.push(Object.values(item));
});
let csvContent = '';
refinedData.forEach(row => {
csvContent += row.join(';') + '\n';
});
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8,' })
const xhr = new XMLHttpRequest();
const url = "./main.php";
xhr.open("POST", url, true);
xhr.onload = function () {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error('Error occurred:', xhr.status, xhr.statusText);
}
document.location.href = "result.html";
};
xhr.send(blob);
}
function displayBorders() {
var answerElements = document.getElementsByClassName("answer");
for (var i = 0; i < answerElements.length; i++) {
answerElements[i].disabled = true;
answerElements[i].onclick = () => {
};
if (i === correctAnswerNumber) {
answerElements[i].style.border = "3px solid #10da10"
} else {
answerElements[i].style.border = "3px solid #d33e3e"
}
nextButton.disabled = false;
}
}
//question and answers
var questionText = "Wie viel zahlt Harry für sein Ticket für den fahrenden Ritter inklusive heißer Schokolade?";
var answers = [
"13 Sickel",
"4 Sickel",
"15 Sickel",
"1 Galleone ",
];
//question text
var questionElement = document.getElementById("question");
questionElement.innerText = questionText;
//button texts
var answerButtons = document.getElementsByClassName("answer");
for (var i = 0; i < answerButtons.length; i++) {
answerButtons[i].innerText = answers[i];
answerButtons[i].style.border = "3px solid #4caf50";
answerButtons[i].onclick = () => {
displayBorders();
};
}
</script>
</body>
</html>