async function loadQuestions() {
const response = await fetch("https://opentdb.com/api.php?amount=10&category=28&type=multiple");
const data = await response.json();
for (let key of Object.keys(data.results)) {
oneQuestionArr.push(data.results[key]); // кладем 1 Object в массив
// console.log(oneQuestionArr);
// totArray.push(oneObj);
}
// console.log(totArray);
totArray = oneQuestionArr;
singlingOutQuestion(totArray);
}
function singlingOutQuestion(array) {
let spec = [];
for (let item = 0; item < array.length; item++) {
spec = array[item];
}
showQuestion(spec);
}
// display Question and Options
function showQuestion(spec /*1 Object*/) {
// console.log(data);
// nullHTMLData();
_checkBtn.disabled = false;
correctAnswer = spec.correct_answer; // OK
// console.log(correctAnswer);
let incorrectAnswers = spec.incorrect_answers;
// console.log(incorrectAnswers); // ok
let optionsList = incorrectAnswers;
// console.log(optionsList);
optionsList.splice(Math.floor(Math.random() * (incorrectAnswers.length + 1)), 0, correctAnswer);
console.log('OPTIONLIST::::', optionsList); // ok - 4 option -OK
_question.innerHTML = `${spec.question}`;
// console.log( _question);
_options.innerHTML = `${optionsList.map((option, index) => `
<li>${index + 1}. <span>${option}</span></li>`)
.join('')}`;
selectOption();
// console.log(correctAnswer);
}
function checkCount() {
askedCount++;
setCount();
if (askedCount === totalQuestion) {
_result.innerHTML += `<p> Your Score is ${correctScore}. </p>`;
_playAgainBtn.style.display = 'block';
_checkBtn.style.display = 'none';
}
else {
setTimeout(() => {
singlingOutQuestion(totArray);
}, 200);
}
}