JSFiddle - React, Tailwind, and code Playground

by Vitaliy

HTML

<button id = 'quiz'>Ask</button>
<div id='text'></div>

CSS

#quiz, #text{
    display:block;
    margin:10px auto;
}
#text{
    width:200px;
    height:50px;
    border:1px solid black;
    padding:10px;
}

JavaScript

var questions = ['waz up?)', 'how old r u?', 'r u fine?', 'what\'s ur name?', 'what abou A?'];
var asked = [];
var text = document.getElementById('text');
document.getElementById('quiz').onclick = function(){
    text.innerHTML = askQuestion();
}

function askQuestion(){ 
    if(asked.length === questions.length) 
        return 'no more questions';
    q = Math.floor(Math.random()*questions.length);
    for(;;){
        if(asked.indexOf(q) === -1)
            break;
        else
            q = Math.floor(Math.random()*questions.length);
            
    }
    asked.push(q);
    return questions[q];
      
}