const apiKey = 'CtJG5HSMq7i1ggbhqnvc6n0x0iFnx9oWwZ6VFmcd';
const apiUrl = 'https://quizapi.io/api/v1/questions';
async function getQuizQuestions(category, difficulty, limit) {
const url = new URL(apiUrl);
url.searchParams.append('apiKey', apiKey);
url.searchParams.append('category', category);
url.searchParams.append('difficulty', difficulty);
url.searchParams.append('limit', limit);
try {
const response = await fetch(url.toString());
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching quiz questions:', error);
return null;
}
}
// Example usage
const category = 'Linux';
const difficulty = 'Easy';
const limit = 5;
getQuizQuestions(category, difficulty, limit)
.then(questions => {
if (questions) {
console.log('Quiz Questions:', questions);
}
});