JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Musik-Quiz</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="start">
<p>Willkommen zum <span class="nowrap">Musik-Quiz!</span></p>
<p>Die <span id="countQa"></span> Fragen sind teils ernst-, teils scherzhaft gemeint.</p>
<button id="starter" class="blink">Start</button>
</div>
<div id="oneMoreTime">
<p><i class="fas fa-frown"></i> Das war wohl <span class="nowrap">nichts ...</span></p>
<p>Die <span id="countQa"></span> Du kannst es aber noch einmal von vorn versuchen.</p>
<button id="repeater" class="blink">Start</button>
</div>
<div id="divQuestion">
<p id="one"><span id="nrQuestion"></span>. Frage</p>
<p><span id="question"></span></p>
</div>
<div id="divAnswers">
<p id="answer1" class="someAnswer"></p>
<p id="answer2" class="someAnswer"></p>
<p id="answer3" class="someAnswer"></p>
<p id="answer4" class="someAnswer"></p>
<div id="rightAnswer"><i class="fas fa-smile"></i> Richtig! Du bist gut ...</div>
<button id="button">nächste Frage</button>
<div id="end">Das war's!</div>
</div>
<script src="main.js"></script>
</body>
</html>
CSS
body,
button {
font-family: "Noto Sans JP", sans-serif;
font-size: 1rem;
color: #444;
background-color: lightskyblue;
}
.nowrap {
white-space: nowrap;
}
* {
box-sizing: border-box;
}
p {
margin: 0;
}
p#one {
font-weight: 700;
margin-bottom: 0.5rem;
}
#start {
display: block;
}
#start p:first-of-type,
#oneMoreTime p:first-of-type {
font-size: 150%;
font-weight: 800;
margin-bottom: 0.5rem;
color: coral;
}
#oneMoreTime p:first-of-type {
color: crimson;
}
#oneMoreTime > p:nth-child(1) > i {
color: crimson;
font-size: 2rem;
margin-right: 0.6rem;
}
#start button,
#oneMoreTime button {
color: white;
background-color: coral;
margin: 2rem 0 0.5rem;
padding: 0.7rem;
font-size: 1.2rem;
font-weight: 700;
cursor: pointer;
display: block;
animation: blink 1.5s infinite;
}
@keyframes blink {
from {
background-color: coral;
}
35% {
background-color: coral;
}
36% {
background-color: darkorange;
}
64% {
background-color: darkorange;
}
65% {
background-color: coral;
}
to {
background-color: coral;
}
}
#divQuestion,
#divAnswers {
display: none;
}
#divQuestion,
#divAnswers,
#start,
#oneMoreTime {
width: 100%;
margin: 1.5rem auto;
padding: 1rem;
background-color: aliceblue;
border-radius: 1rem;
box-shadow: 0 0 1rem rgba(0, 0, 0, 0.2);
}
@media (min-width: 768px) {
#divQuestion,
#divAnswers,
#start,
#oneMoreTime {
width: 70vw;
}
}
@media (min-width: 992px) {
#divQuestion,
#divAnswers,
#start,
#oneMoreTime {
width: 50vw;
}
}
@media (min-width: 1200px) {
#divQuestion,
#divAnswers,
#start,
#oneMoreTime {
width: 35vw;
}
}
#oneMoreTime {
display: none;
}
#rightAnswer {
color: white;
background-color: yellowgreen;
font-weight: 700;
margin-top: 1.5rem;
border-radius: 0.5rem;
padding: 1rem;
display: none;
}
#rightAnswer i {
color: white;
font-size: 1.5rem;
margin-right: 0.5rem;
}
button {
...
JavaScript
'use strict';
// Fragen
const questions = [
{
question: 'Welche Band veröffentlichte 1980 das Album "Paris"?',
answers: ['Queen', 'Visage', 'Supertramp', 'ELO'],
isCorrect: [false, false, true, false]
},
{
question: 'Auf welchem Pink-Floyd-Album wird eine Atombombe abgeworfen?',
answers: ['The Wall', 'The Final Cut', 'The Endless River', 'The Dark Side of the Moon'],
isCorrect: [false, true, false, false]
},
{
question: 'Natalie Merchant war Sängerin der <span class="nowrap">10,000 Maniacs</span>. Wie hieß ihr erstes Soloalbum?',
answers: ['Tigerlily', 'Tiger Teeth', 'The Jaw Of The Tiger', 'Tigerlove'],
isCorrect: [true, false, false, false]
}
];
// Variablen
let i = 0;
const answerRight = document.getElementById('rightAnswer');
const divQuestion = document.getElementById('divQuestion');
const divAnswers = document.getElementById('divAnswers');
const start = document.getElementById('start');
const end = document.getElementById('end');
const oneMoreTime = document.getElementById('oneMoreTime');
const button = document.getElementById('button');
const repeater = document.getElementById('repeater');
// Funktionen
function buildQuestions() {
document.getElementById('nrQuestion').innerHTML = i + 1;
document.getElementById('question').innerHTML = questions[i].question;
for (let j = 0; j < questions[i].answers.length; j++) {
document.getElementById('answer' + (j + 1)).innerHTML = questions[i].answers[j];
}
answerRight.style.display = 'none';
end.style.display = 'none';
}
function startGame() {
divQuestion.style.display = 'block';
divAnswers.style.display = 'block';
start.style.display = 'none';
}
function resetAnswer() {
let x, z;
x = document.querySelectorAll(".someAnswer");
for (z = 0; z < x.length; z++) {
x[z].style.backgroundColor = "coral";
}
}
function nextQuestion() {
i++;
buildQuestions();
answerRight.style.display = 'none';
button.style.display = 'none';
...