
Hi, welcome here in this tutorial we are going to develop a React Quiz App and also use Tailwind CSS for styling, The prerequisites for this project are as follows:
- Node.js should be installed in your system.
- Create a brand new ReactJs project. Just copy the code below:
code to create React js project:
npx create-react-app my-app
after it run the below command:
cd my-app
after it run the below commands to install Tailwind css into your project:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
and then install the following package:
npm i react-color
after installation run the following command to start the app:
npm run start
The brand-new React Js project should look like this:

Here is your code for the App.js file, copy the code below and paste it into your App.js file:
import React, { useState } from 'react'
const App = () => {
const [currentQuestion, setcurrentQuestion] = useState(0);
// we will toggle the show score
const [showScore, setshowScore] = useState(false);
const [score, setscore] = useState(0);
// lets add some questions
const allQuestions = [
{
text: 'Who is the CEO of Amazon?',
options: [
{ answerText: 'Jeff', isCorrect: true },
{ answerText: 'Mark', isCorrect: false },
{ answerText: 'Elon', isCorrect: false },
],
},
{
text: 'Who is the CEO of Facebook?',
options: [
{ answerText: 'Jeff', isCorrect: false },
{ answerText: 'Mark', isCorrect: true },
{ answerText: 'Elon', isCorrect: false },
],
},
{
text: 'Who is the CEO of Tesla?',
options: [
{ answerText: 'Jeff', isCorrect: false },
{ answerText: 'Mark', isCorrect: false },
{ answerText: 'Elon', isCorrect: true },
],
},
{
text: 'Who is the CEO of Google?',
options: [
{ answerText: 'Jeff', isCorrect: false },
{ answerText: 'Mark', isCorrect: false },
{ answerText: 'Larry', isCorrect: true },
],
},
{
text: 'Who is the CEO of Youtube?',
options: [
{ answerText: 'Javed', isCorrect: true },
{ answerText: 'Mark', isCorrect: false },
{ answerText: 'Elon', isCorrect: false },
],
},
]
const handleAnswerOptions = (isCorrect) => {
if (isCorrect) {
setscore(score + 1);
}
const handleNextQuestion = currentQuestion + 1;
if (handleNextQuestion < allQuestions.length) {
setcurrentQuestion(handleNextQuestion);
} else {
setshowScore(true);
}
}
return (
{
showScore ? (
<>
You scored {score} out of {allQuestions.length}
>
) : (
<>
Question {currentQuestion + 1}/{allQuestions.length}
{allQuestions[currentQuestion].text}
{
allQuestions[currentQuestion].options.map((options) => (
))
}
>
)
}
)
}
export default App
Here is your code for the index.css file, copy the code below and paste it into your index.css file:
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
Here is your code for tailwind.config.js copy the code below and paste it into tailwind.config.js.
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
After writing the code into the files (don’t forget to save it ,) you can run the command below:
npm start