Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ function App() {
setSelectedAnswer(selection);
};

const nextQuestion = async() => {
try {
const response = await fetch("https://opentdb.com/api.php?amount=1&category=9&type=multiple");
const data = await response.json();
const newQuestion = data.results[0];

setQuestionData(newQuestion); // Update the question data with the new question
setSelectedAnswer(null); // Reset the selected answer
} catch (error) {
console.error("Failed to fetch a new question", error);
}
};

let card;

if (selectedAnswer) {
Expand Down Expand Up @@ -41,7 +54,7 @@ function App() {
<div className="w-100 my-5 d-flex justify-content-center align-items-center">
<div style={{ maxWidth: "45%" }}>
<h1 className="text-center">Trivia App</h1>
<button className="btn btn-success">Next Question</button>
<button className="btn btn-success" onClick={nextQuestion}>Next Question</button>
{card}
</div>
</div>
Expand Down