Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.
Open
Show file tree
Hide file tree
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
25 changes: 24 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,34 @@ function App() {
);
}

const setQuestionCard = (event) =>
{

fetch('https://opentdb.com/api.php?amount=1&category=9&type=multiple')
.then((response) => response.json())
.then((data) =>{
console.log(data)
setQuestionData(data.results[0]);
});
setSelectedAnswer(false);
let options = [
questionData.correct_answer,
...questionData.incorrect_answers,
];
card = (
<QuestionCard
question={questionData.question}
options={shuffleArray(options)}
selectAnswer={selectAnswer}
/>
);
}

return (
<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 onClick={setQuestionCard} className="btn btn-success">Next Question</button>
{card}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ResultCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
function ResultCard({ correct, answer }) {
return (
<>
<h2>You answer is {correct ? `correct ✅` : `wrong ❌`}</h2>
<h2>Your answer is {correct ? `correct ✅` : `wrong ❌`}</h2>
{!correct && <p>The correct answer was {answer}</p>}
</>
);
Expand Down