Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript QuizApp</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
<h1>General Quiz</h1>

<div class="quiz_container">

  <div class="question-container" id="questionline">

  </div>
  <div class="question-options">
    <ul id="ul">
      <li id="op1" onclick="button(this)"></li>
      <li id="op2" onclick="button(this)"></li>
      <li id="op3" onclick="button(this)"></li>
      <li id="op4" onclick="button(this)"></li>
    </ul>
  </div>
  <div class="result">
    <div class="next">
      <button type="button"  onclick="next()" id="btn">Next</button>

    </div>
    <div class="result-count">
      Score: <span id="scoreCard">0</span>
    </div>

  </div>

</div>


    <script src="index.js" charset="utf-8"></script>
  </body>
</html>

              
            
!

CSS

              
                body {
  background-image: linear-gradient(to right, #9c27b0 25%, #2575fc 75%);
  padding: 0;
  margin: 0;
  font-family: sans-serif;
}
h1 {
  color: white;
  text-align: center;
}
* {
  box-sizing: border-box;
}

.quiz_container {
  height: 450px;
  width: 700px;
  background-color: grey;
  margin: 30px auto;
  border-radius: 10px;
  padding: 15px;
}

.quiz_container .question-container {
  height: 60px;
  width: 100%;
  background-color: purple;
  border-radius: 8px;
  padding: 20px;
  font-size: 20px;
  color: #fff;
  text-align: center;
  float: left;

}

.quiz_container .quiz-options {
  float: left;
  width: 100%;
}

.quiz_container .quiz-options  ul {
  list-style: none;
  padding: 0;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
 ul li {
  display: inline-block;
  background-color: #607d8b;
  width: 47%;
  padding: 15px;
  border-radius: 10px;
  float: left;
  margin-top: 30px;
  margin-right: 10px;
  font-size: 20px;
  color: #fff;
  box-shadow: 0px 3px 0px purple;
  cursor: pointer;
  text-align: center;
}

ul li:active {
  box-shadow: 0px 0px 0px purple;
}

 ul li.correct{
  background-color: green;
}
 ul li.wrong{
   background-color: red;
 }

 .result {
  float: left;
  width: 100%;
  padding: 35px 30px;
}

 .result .next {
  width: 40%;
  float: left;
}

  button {
  color: #fff;
  background-color: #800080;
  border-radius: 8px;
  padding: 15px 30px;
  margin-top: 20px;
  cursor: pointer;
  border: none;
  font-size: 20px;
}

 .result .result-count {
  width: 60%;
  float: left;
  margin-top: 30px;
  color: #331833;
  font-size: 20px;
  text-transform: uppercase;
}

span {
  background-color: purple;
  padding: 5px 20px;
  border-radius: 8px;
  color: #fff;
}


              
            
!

JS

              
                

var uList = document.getElementById("ul");
var btn = document.getElementById("btn");
var scoreCard = document.getElementById("scoreCard");
var quizBox = document.getElementById("questionline");
var op1 = document.getElementById("op1");
var op2 = document.getElementById("op2");
var op3 = document.getElementById("op3");
var op4 = document.getElementById("op4");



var myApp = {
  questions: [
    {
   q: "Who is the C.E.O of facebook?", options:["Samuel Abah", "Donald Trump", "Muhammadu Buhari", "Mark Zuckerberg"], answer:4
 },

  { q: "What is the full meaning of DOM?", options:["Document Outlet Model", "Document Object Model", "Downward Object Model", "Deep Object Model"], answer:2
},

{  q: "Which of these is not a HTML element?", options:["h1 tag", "span tag", "anchor tag", "none of the above"], answer:4
},

{  q: "One of these is not a design tool?", options:["Figma", "Adobe XD", "Adobe Illustrator", "Node js"], answer:4
},

{  q: "One of these is not a frontend framework?", options:["Bootsrap", "flutter", "Tailwind CSS", "Vue js"], answer:3
}

],

index:0,
load:function() {
  if (this.index<=this.questions.length-1) {

  quizBox.innerHTML=this.index + 1 + "." + this.questions[this.index].q;
  op1.innerHTML=this.questions[this.index].options[0];
  op2.innerHTML=this.questions[this.index].options[1];
  op3.innerHTML=this.questions[this.index].options[2];
  op4.innerHTML=this.questions[this.index].options[3];
    this.scoreCard();
} else {
  quizBox.innerHTML="End of Quiz."
  op1.style.display="none";
  op2.style.display="none";
  op3.style.display="none";
  op4.style.display="none";
  btn.style.display="none";
}

},

next:function() {
  this.index++;
  this.load();
},

  check:function(ele) {
        var id=ele.id.split("");
        if(id[id.length-1]==this.questions[this.index].answer) {
          this.score++;
          ele.className="correct";
          this.scoreCard();
        } else {
          ele.className="wrong";
        }
  },
  notClickAble:function() {
    for(let i=0; i<ul.children.length;i++) {
      ul.children[i].style.pointerEvents="none";
    }
  },

  clickAble:function() {
    for(let i=0; i<ul.children.length;i++) {
      ul.children[i].style.pointerEvents="auto";
      ul.children[i].className="";
    }
  },

  score:0,
  scoreCard: function() {
      scoreCard.innerHTML=this.score+"/"+this.questions.length;
  }


}

    window.omload=myApp.load();

    function button(ele) {

      myApp.check(ele);
      myApp.notClickAble();
    }

    function next() {
      myApp.next();
      myApp.clickAble();
    }

              
            
!
999px

Console