Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added question iteration. #20

Merged
merged 8 commits into from
Aug 1, 2024
Merged
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
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
Loading