Skip to content

Commit ffde96f

Browse files
Do something to store API data
1 parent 8e922e2 commit ffde96f

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

public/serviceworker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const filesToCache = [
1313
"/static/js/bundle.js",
1414
"/static/js/1.chunk.js",
1515
"/static/js/0.chunk.js",
16+
"/static/js/main.chunk.js.map",
1617

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

src/services/quiz_service.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
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[]) => [...array].sort(() => Math.random() - 0.5)
4+
const shuffleAnswers = (array: any[]) =>
5+
[...array].sort(() => Math.random() - 0.5);
56

67
// Get Data from API
7-
export const getQuizDetails = async (totalQuestions: number,category: number,level: string): Promise<QuestionType[]> => {
8-
8+
export const getQuizDetails = async (
9+
totalQuestions: number,
10+
category: number,
11+
level: string
12+
): Promise<QuestionType[]> => {
913
const response = await fetch(
1014
`https://opentdb.com/api.php?amount=${totalQuestions}&category=${category}&difficulty=${level}&type=multiple`
11-
)
12-
13-
14-
console.log(response)
15-
let { results } = await response.json()
16-
15+
);
16+
let { results } = await response.json();
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-
27-
return quiz
28-
}
24+
};
25+
});
26+
return quiz;
27+
};

0 commit comments

Comments
 (0)