Skip to content

Commit 8e922e2

Browse files
Configure the response
1 parent 45939ec commit 8e922e2

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

public/serviceworker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const filesToCache = [
1212
"/static/js/main.chunk.js",
1313
"/static/js/bundle.js",
1414
"/static/js/1.chunk.js",
15+
"/static/js/0.chunk.js",
1516

1617
"/web-fonts/css/all.min.css",
1718

src/services/quiz_service.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
import { Quiz, QuestionType } from "../types/quiz_types";
1+
import { Quiz, QuestionType } from "../types/quiz_types"
22

33
// Shuffle Answers functions
4-
const shuffleAnswers = (array: any[]) =>
5-
[...array].sort(() => Math.random() - 0.5);
4+
const shuffleAnswers = (array: any[]) => [...array].sort(() => Math.random() - 0.5)
65

76
// Get Data from API
8-
export const getQuizDetails = async (
9-
totalQuestions: number,
10-
category: number,
11-
level: string
12-
): Promise<QuestionType[]> => {
7+
export const getQuizDetails = async (totalQuestions: number,category: number,level: string): Promise<QuestionType[]> => {
8+
139
const response = await fetch(
1410
`https://opentdb.com/api.php?amount=${totalQuestions}&category=${category}&difficulty=${level}&type=multiple`
15-
);
16-
let { results } = await response.json();
11+
)
12+
13+
14+
console.log(response)
15+
let { results } = await response.json()
16+
1717
const quiz: QuestionType[] = results.map((questionObj: Quiz) => {
1818
return {
1919
question: questionObj.question,
2020
answer: questionObj.correct_answer,
2121
options: shuffleAnswers(
2222
questionObj.incorrect_answers.concat(questionObj.correct_answer)
2323
),
24-
};
25-
});
26-
return quiz;
27-
};
24+
}
25+
})
26+
27+
return quiz
28+
}

0 commit comments

Comments
 (0)