JSFiddle - React, Tailwind, and code Playground
by Ulrich Bangert
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 id="testIt">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> <span id="countTrue"></span> richtig ...</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 legendäre Pop-Band der 70er veröffentlichte 2021 neue Songs?',
answers: ['BABA', 'ABAB', 'BAAB', 'ABBA'],
isCorrect: [false, false, false, true]
},
{
question: 'Wie hieß der Chef der Dire Straits?',
answers: ['Knark Mopfler', 'Kropf Markler', 'Krank Flomper', 'Mark Knopfler'],
isCorrect: [false, false, false, true]
},
{
question: 'Welche Band veröffentlichte 1980 das Album "Paris"?',
answers: ['Queen', 'Visage', 'Supertramp', 'ELO'],
isCorrect: [false, false, true, false]
},
{
question: 'Welche Sängerin ist mit 60 Jahren noch genauso intelligent wie mit 20?',
answers: ['Nena', 'Nane', 'Nana', 'Nene'],
isCorrect: [true, false, false, 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: 'Wie hieß der Sänger der Scorpions?',
answers: ['Kleine Maus', 'Klaun Meise', 'Klaus Meine', 'Mies Launek'],
isCorrect: [false, false, true, false]
},
{
question: 'Welche Sängerin landete 2021 mit <span class="nowrap">"Good 4 U"</span> einen Hit?',
answers: ['Olivia Rodrigo', 'Ava Max', 'Lena', 'Miley Cyrus'],
isCorrect: [true, false, false, false]
},
{
question: 'Natalie Merchant war Sängerin der <span class="nowrap">10,000 Maniacs</span>. Wie hieß ihr erstes Soloalbum?',
answers: ['Tigerlove', 'Tiger Teeth', 'The Jaw Of The Tiger', 'Tigerlily'],
isCorrect: [false, false, false, true]
},
{
question: 'Ende der 1960er-Jahre revolutionierte ein Synthesizer-Modell die moderne Musik – wie heißt es?',
answers: ['Moog', 'Mood', 'Melodyne', 'Maxima'],
isCorrect: [true, false, false, false]
},
{
question: 'Jeff Lynn war der Chef welcher Band?',
answers: ['Electric Flight Orchestra', 'Electric Fight...