-
Notifications
You must be signed in to change notification settings - Fork 7
/
Home.vue
163 lines (145 loc) · 4.25 KB
/
Home.vue
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
<template>
<main class="flex h-screen items-center justify-center bg-gray-100">
<!-- quiz container -->
<div
class="overflow-hidden bg-white flex-none container relative shadow-lg rounded-lg px-12 py-6"
>
<img
src="@/assets/images/abstract.svg"
alt=""
class="absolute -top-10 left-0 object-none"
/>
<!-- contents -->
<div class="relative z-20">
<!-- score container -->
<div class="text-right text-gray-800">
<p class="text-sm leading-3">Score</p>
<p class="font-bold">60</p>
</div>
<!-- timer container -->
<div class="bg-white shadow-lg p-1 rounded-full w-full h-5 mt-4">
<div class="bg-blue-700 rounded-full w-11/12 h-full"></div>
</div>
<!-- question container -->
<div
class="rounded-lg bg-gray-100 p-2 neumorph-1 text-center font-bold text-gray-800 mt-8"
>
<div class="bg-white p-5">
{{ currentQuestion.question }}
</div>
</div>
<!-- options container -->
<div class="mt-8">
<!-- option container -->
<div v-for="(choice, item) in currentQuestion.choices" :key="item">
<div
class="neumorph-1 option-default bg-gray-100 p-2 rounded-lg mb-3 relative"
:ref="optionChosen"
@click="onOptionClicked(choice, item)"
>
<div
class="bg-blue-700 p-1 transform rotate-45 rounded-md h-10 w-10 text-white font-bold absolute right-0 top-0 shadow-md"
>
<p class="transform -rotate-45">+10</p>
</div>
<div class="rounded-lg font-bold flex p-2">
<!-- option ID -->
<div class="p-3 rounded-lg">{{ item }}</div>
<!-- option name -->
<div class="flex items-center pl-6">{{ choice }}</div>
</div>
</div>
</div>
</div>
<!-- progress indicator container -->
<div class="mt-8 text-center">
<div class="h-1 w-12 bg-gray-800 rounded-full mx-auto"></div>
<p class="font-bold text-gray-800">2/10</p>
</div>
</div>
</div>
</main>
</template>
<style scoped>
.neumorph-1 {
box-shadow: 6px 6px 18px rgba(0, 0, 0, 0.09), -6px -6px 18px #ffffff;
}
.container {
max-width: 400px;
border-radius: 25px;
}
</style>
<script>
import { onMounted, ref } from "vue";
export default {
setup() {
// data
let questionCounter = ref(0);
const currentQuestion = ref({
question: "",
answer: 1,
choices: [],
});
const questions = [
{
question:
"Which programming language shares its name with an island in Indonesia?",
answer: 1,
choices: ["Java", "Python", "C", "Jakarta"],
},
{
question: "On Twitter, what is the character limit for a Tweet?",
answer: 3,
choices: ["120", "160", "140", "100"],
},
{
question: "What does the 'MP' stand for in MP3?",
answer: 4,
choices: [
"Music Player",
"Multi Pass",
"Micro Point",
"Moving Picture",
],
},
];
const onQuizStart = () => {
currentQuestion.value = questions[questionCounter.value];
};
// methods/functions
let itemsRef = [];
const optionChosen = (element) => {
if (element) {
itemsRef.push(element);
}
};
const onOptionClicked = (choice, item) => {
const divContainer = itemsRef[item];
const optionID = item + 1;
if (currentQuestion.value.answer == optionID) {
console.log("you are correct");
divContainer.classList.add("option-correct");
divContainer.classList.remove("option-default");
} else {
console.log("you are wrong");
divContainer.classList.add("option-wrong");
divContainer.classList.remove("option-default");
}
console.log(choice, item);
};
// lifecycle hooks
onMounted(() => {
onQuizStart();
});
// return
return {
currentQuestion,
questions,
questionCounter,
onQuizStart,
onOptionClicked,
optionChosen,
};
},
};
</script>