Skip to content

Commit

Permalink
added question iteration.
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-amy committed Aug 1, 2024
1 parent e218254 commit 321c9ea
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function App() {
<Route path='/quiz'
element={<Quiz />} />
</Routes>
<Footer />
<Footer/>
</Router>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import Hamburger from '../Hamburgerbutton/Hamburgerbutton';

const logo = require('../ImageAssets/marsiokartlogo.jpg')
const logo = require('../ImageAssets/marsiokartlogo.png')

const Header: React.FC = () => {
const handleHamburgerClick = () => {
Expand Down
Binary file added src/ImageAssets/marsiokartlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 18 additions & 8 deletions src/QuestionDisplay/QuestionDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { getQuizQuestions } from "../getQuizQuestions/getQuizQuestions";
import { getQuizQuestions, Answer, Question } from "../getQuizQuestions/getQuizQuestions";
import { Quiz } from "../Quiz/Quiz";

export function QuestionDisplay() {
const questions = getQuizQuestions();
interface QuestionDisplayProp{
question: Question;
}

const question = questions[Math.floor(Math.random() * questions.length)];
export function QuestionDisplay(props: QuestionDisplayProp) {
// const questions = getQuizQuestions();

// const question = questions[Math.floor(Math.random() * questions.length)];

// function updateCurrentIndex() {
// setCurrentIndex(currentIndex + 1);
// }

return (
<div>
{question.question} <br/>
<input type="radio" name="answer" id="radio-button1" value="0" /> {question.answers[0].answer} <br/>
<input type="radio" name="answer" id="radio-button2" value="1" /> {question.answers[1].answer} <br/>
<input type="radio" name="answer" id="radio-button3" value="2" /> {question.answers[2].answer} <br/>
{props.question.question} <br/>
<input type="radio" name="answer" id="radio-button1" value="0" /> {props.question.answers[0].answer} <br/>
<input type="radio" name="answer" id="radio-button2" value="1" /> {props.question.answers[1].answer} <br/>
<input type="radio" name="answer" id="radio-button3" value="2" /> {props.question.answers[2].answer} <br/>
{/* <button type="submit" className="submit-answer" onClick={() => updateCurrentIndex() }>Submit</button> */}
</div>

)
Expand Down
30 changes: 29 additions & 1 deletion src/Quiz/Quiz.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import { QuestionDisplay } from "../QuestionDisplay/QuestionDisplay"
import { getQuizQuestions } from "../getQuizQuestions/getQuizQuestions"
import { useState, useEffect } from "react";


export function Quiz () {
const listOfQuestions = getQuizQuestions();

const [currentIndex, setCurrentIndex] = useState<number>(0);
const [buttonText, setButtonText] = useState<string>("Next");

const question = listOfQuestions[currentIndex]

useEffect(() => {
if (currentIndex === listOfQuestions.length-1) {
setButtonText("Finish")
}
}, [currentIndex]);


let lastQuestion = false;

function updateCurrentIndex() {
if (currentIndex < listOfQuestions.length-1) {
setCurrentIndex(currentIndex + 1);
}
}

return (
<QuestionDisplay/>
<div>
<QuestionDisplay question={question}/>
<button type="submit" className="quiz-button" onClick={() => updateCurrentIndex()}>{buttonText}</button>
</div>
)
}
4 changes: 2 additions & 2 deletions src/getQuizQuestions/getQuizQuestions.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
type Answer = {
export type Answer = {
answer: string,
isCorrect: boolean
}

type Question = {
export type Question = {
question: string,
answers: Array<Answer>
}
Expand Down

0 comments on commit 321c9ea

Please sign in to comment.