-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
63 lines (53 loc) · 2.31 KB
/
script.js
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
let CutegirlAnswers = JSON.parse(localStorage.getItem('CutegirlAnswers')) || [];
function handleAnswer(questionNumber, isCorrect, nextPage) {
CutegirlAnswers[questionNumber - 1] = isCorrect;
localStorage.setItem('CutegirlAnswers', JSON.stringify(CutegirlAnswers));
history.replaceState(null, '', nextPage);
location.href = nextPage;
}
function initializePage() {
history.replaceState(null, '');
window.addEventListener('popstate', function(event) {
location.href = 'summary.html';
});
}
function startQuiz() {
CutegirlAnswers = [];
localStorage.setItem('CutegirlAnswers', JSON.stringify(CutegirlAnswers));
location.href = 'question1.html';
}
function showSummary() {
const CutegirlAnswers = JSON.parse(localStorage.getItem('CutegirlAnswers')) || [];
const correctCount = CutegirlAnswers.filter(answer => answer).length;
const summaryElement = document.getElementById('summary');
const congratulationsElement = document.getElementById('congratulations');
const shareButton = document.getElementById('shareButton');
summaryElement.innerText = `You got ${correctCount} out of 5 !`;
if (correctCount === 5) {
congratulationsElement.innerText = 'You know me so well Bestie \uD83D\uDC8B';
congratulationsElement.style.fontSize = '25px';
shareButton.style.display = 'block';
} else if (correctCount <= 1) {
congratulationsElement.innerText = '🥺 its okay you can retest';
congratulationsElement.style.fontSize = '25px';
shareButton.style.display = 'block';
} else {
congratulationsElement.innerText = `Wow ${correctCount}? not bad 🥰 `;
congratulationsElement.style.fontSize = '25px';
shareButton.style.display = 'block';
}
}
function shareScore() {
const CutegirlAnswers = JSON.parse(localStorage.getItem('CutegirlAnswers')) || [];
const correctCount = CutegirlAnswers.filter(answer => answer).length;
const shareText = `I scored ${correctCount} out of 5 on Nancy bestie quiz!! here the link 👇🏻👇🏻`;
if (navigator.share) {
navigator.share({
title: 'Quiz Score',
text: shareText,
url: 'https://urmxrainbow.github.io/Bestie/',
});
} else {
alert('Sharing not supported in this browser.');
}
}