I’m trying to have on array up with its values but it’s coming up two. I think i’m looping through it two times, thats why got two arrays. Would be nice if somebody could point me in right direction. Cause i’m stuck.
$(function() {
$.getJSON('https://opentdb.com/api.php?amount=10', showQuestions)
function showQuestions(jsonData) {
$.each(jsonData.results, function(index, val) {
let questions = jsonData.results[index];
//console.log(questions);
let answers = [];
$.each(jsonData, function(i, val) {
answers.push(questions.incorrect_answers);
//tried to put [i] after the questions but arrays geting undefined
//console.log(answers);
});
answers.push(questions.correct_answer);
answers.sort();
console.log(answers);
});
}
});