JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Aplikacja quizu</title>
<meta name="keywords" content="aplikacja, quiz, pytania, odpowiedzi">
<meta name="description" content="Podstawowa aplikacja do quizu">
<link rel="stylesheet" href="style.css">
<script src="index.js" defer></script>
</head>
<body>
<div class="content">
<div class="content-quiz">
<div class="content-quiz-questions">
<h2 id="header-questions">Question</h2>
</div>
<div class="content-quiz-answers">
<ul>
<li>
<input type="radio" id="answer_a" name="answer" class="answer">
<label id="a" for="answer_a">Question</label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="answer_b" name="answer" class="answer">
<label id="b" for="answer_b">Question</label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="answer_c" name="answer" class="answer">
<label id="c" for="answer_c">Question</label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="answer_d" name="answer" class="answer">
<label id="d" for="answer_d">Question</label>
</li>
</ul>
</div>
</div>
<div class="btn-quiz">
<button type="submit">Wyślij</button>
</div>
</div>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #b8c6db;
background-image: linear-gradient(315deg, #b8c6db 0%, #f5f7fa 100%);
font-family: 'Poppins', sans-serif;
}
.content{
width: 600px;
max-width: 100%;
background-color: #fff;
overflow: hidden;
border-radius: 10px;
box-shadow: 0 0 10px 2px rgba(100, 100, 100, 0.1);
}
.content .content-quiz{
padding: 4rem;
}
.content-quiz .content-quiz-questions h2{
padding: 1rem;
text-align: center;
margin: 0;
}
.content-quiz .content-quiz-answers ul{
list-style-type: none;
padding: 0;
}
.content-quiz .content-quiz-answers ul li{
font-size: 1.2rem;
margin: 1rem 0;
}
.content .btn-quiz{
position: relative;
width: 100%;
}
.content .btn-quiz button{
width: inherit;
padding: 1.3rem;
display: block;
color: white;
cursor: pointer;
font-size: 1.1rem;
background-color: #8e44ad;
transition: background-color, 2s;
}
.content .btn-quiz button:hover{
background-color: #732d91;
}
JavaScript
const headQuest = document.getElementById('header-questions');
headQuest.innerHTML = randomComputerQuestions(randomComputerQuestions);
const answerA = document.getElementById('a');
answerA.innerHTML = answerQuizA(randomComputerAnswers);
const answerB = document.getElementById('b');
answerB.innerHTML = answerQuizB(randomComputerAnswers);
const answerC = document.getElementById('c');
answerC.innerHTML = answerQuizC(randomComputerAnswers);
const answerD = document.getElementById('d');
answerD.innerHTML = answerQuizD(randomComputerAnswers);
function randomComputerQuestions() {
const arrQuest = [ 'Jaki był najcześciej używany język programowania w 2019?' ];
return arrQuest[Math.floor(Math.random() * 1)];
}
function randomComputerAnswers() {
const arrAnswer = [ 'Java', 'C', 'Python', 'JS' ];
return arrAnswer[Math.floor(Math.random() * 4)];
}
function firstOfFourQuestions(randomComputerQuestions) {
let firstQuestion = randomComputerQuestions();
return firstQuestion;
}
function answerQuizA(randomComputerAnswers) {
let answerA = randomComputerAnswers();
return answerA;
}
function answerQuizB(randomComputerAnswers) {
let answerA = randomComputerAnswers();
return answerA;
}
function answerQuizC(randomComputerAnswers) {
let answerA = randomComputerAnswers();
return answerA;
}
function answerQuizD(randomComputerAnswers) {
let answerA = randomComputerAnswers();
return answerA;
}