Skip to content

Commit

Permalink
Merge pull request #20 from techswitch-learners/mm-307-question-itera…
Browse files Browse the repository at this point in the history
…tion

added question iteration.
  • Loading branch information
sun-amy authored Aug 1, 2024
2 parents 0e8e65c + 4c8c088 commit 547e64f
Show file tree
Hide file tree
Showing 6 changed files with 36 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 @@ -18,7 +18,7 @@ function App() {
<Route path='/quiz'
element={<Quiz username={username}/>} />
</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
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import Hamburger from '../Hamburgerbutton/Hamburgerbutton';
import './Header.scss'

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

const Header: React.FC = () => {

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.
17 changes: 9 additions & 8 deletions src/QuestionDisplay/QuestionDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { getQuizQuestions } from "../getQuizQuestions/getQuizQuestions";
import { Question } from "../getQuizQuestions/getQuizQuestions";

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

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

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/>
</div>

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

interface QuizProps{
username:string;
}

export function Quiz (props:QuizProps) {
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, listOfQuestions.length]);

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

return (
<div>
User : {props.username}
<QuestionDisplay/>
<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 547e64f

Please sign in to comment.