So I'm doing a quiz.And i want to check if || while document contains alert.So if the document contains alert then i want to append my Button Next.So this is my idea:
if(document.contains(alert)) {
const buttonNext = document.createElement("button")
buttonNext.innerText = "Next"
} else {
!document.append(buttonNext)
}
This is the quiz section:
const myBtns = document.querySelectorAll('.Btn')
myQuestionAndAnswers.forEach(item => {
const myAnswers = item.Answers
const myQuestion = item.Question
const mySecondStage = item.SecondStage
myFunctionForOptions(myAnswers , myQuestion)
})
function myFunctionForOptions(answers, question) {
const [firstObj, secondObj] = answers // ES6 definening 2 Object in one const variable
let j
const remainder = 30 % answers.length + 2
console.log(remainder)
for(j = 0;j < (myBtns.length / answers.length + remainder);j++) { //Replacing my Buttons with j
const typeOfInput = myBtns[j].getAttribute('value') // Getting the value of the input
myBtns[j].addEventListener('click', (e) => {
console.log(e.target)
if(firstObj.option == typeOfInput) { //Checking if the firstObj is the same as the value of the input
const myTrueAnswer = alert('Hey you got the answer right.Congratulations🎉!')
} else {
const myFalseAnswer = alert('You got the answer wrong try next time😔...')
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment