css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
<html>
<head>
    <title>Game of Thrones Quiz</title>
        <link type="text/css" rel="stylesheet" href="stylesheet.css" />
        <meta name="viewport" content="width=device-width">
        <link href='https://fonts.googleapis.com/css?family=Oswald:300' rel='stylesheet' type='text/css'>
</head>
<body ontouchstart="">
<h1>Game of Thrones</h1>

<h2></h2>

<p id="image"></p>
<div id="try-again-container" style="display:none;"><button id="try-again">Try Again</button></div>
<ul>
    <li><button class="submit-answer" id="0"></button></li>
    <li><button class="submit-answer" id="1"></button></li>
    <li><button class="submit-answer" id="2"></button></li>
    <li><button class="submit-answer" id="3"></button></li>
</ul>

<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script language="javascript" src="quiz.js"></script>
</body>
</html>

            
          
!
            
              body {
	color: #413D3D;
	font-family: 'Oswald', sans-serif;
	width: 95%;
  text-align: center;
	margin: 0 auto;
}

* {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

ul {
   list-style-type:none;
  margin: 0 auto;
   list-style:none;
   padding:0;
}

li {
  list-style:none;
}

button {
      width: 220px;
      font-size: 20px;
      margin:12px 0;
      padding: 10px 0;
      background-color: #516363;
      color: #fff;
      font-family: 'Oswald', sans-serif;
	  -webkit-border-radius: 1000px;
      border-radius: 1000px;
      outline: none;
      border: none;
}

button:active {
      background-color: #95a5a6;
}

.correctStyle {
      background-color: #2ecc71;
}

.incorrectStyle {
      background-color: #e74c3c;
}

img {
	border-radius: 5px;
}

            
          
!
            
              
$(document).ready(function() {
start(questionNumber);

$(".submit-answer").on("click", function(event) {

    var userAnswer = parseInt($(this).attr("id"));
    answerCheck(userAnswer);

    setTimeout(function() {
                $(".submit-answer").removeClass("correctStyle incorrectStyle");
                 start(questionNumber);
             }, 1500)

     questionNumber++;
  });

});

var questionNumber = 0,
    totalCorrect = 0,
    optionFinal = 0;

var allQuestions = [
     {
        question: 'Who said, "My real father lost his head at Kings Landing. I made a choice, and I chose wrong."',
        choices: ["Robb Stark", "Jon Snow", "Theon Greyjoy", "Arya Stark"],
        answer: 2}
    ,{
        question: "What does Valar Morghulis mean?",
        choices: ["All men must die", "What is dead may never die", "Never say never", "All men must first live"],
        answer: 0}
    ,{
        question: "Which GOT character played Hermoine Granger's mom in Harry Potter?",
        choices: ["Melisandre", "Catelyn Stark", "Cersei Lannister", "Alerie Tyrell"],
        answer: 1}
    ,{
        question: 'Who said, "You knelt as boys, now rise as men of the Nights Watch."?',
        choices: ["Maester Aemon", "Eddard Stark", "Jeor Mormont", "Alliser Thorne"],
        answer: 2}
    ,{
        question: "What is Daenerys Targaryens brothers name?",
        choices: ["Varys", "Viserys", "Aerys", "Aegon"],
        answer: 1}
    ,{
        question: "What is a big fear of the Dothraki?",
        choices: ["Fire", "Salt water", "Heavy stone", "Crows"],
        answer: 1}
    ,{
        question: "How many swords make up the Iron Throne?",
        choices: ["500", "1000", "2000", "5000"],
        answer: 1}
    ,{
        question: "What were Jon Arryn's final words?",
        choices: ["Winter is coming", "Beware of the white walkers", "The seed is strong", "Beware the dwarf"],
        answer: 2}
    ,{
        question: "Who built the Iron Throne?",
        choices: ["Aerys the Mad King", "Aegon The Unlikely", "Aegon the Conqueror", "Aegon the Destroyer"],
        answer: 2}
    ,{
        question: "Which knight takes a lance through the neck while jousting?",
        choices: ["Ser Hugh of the Vale", "Ser Barristan Selmy", "Ser Ilyn Payne", "Ser Gregor Clegane"],
        answer: 0}
  ];

var result = [
    {
      image: "http://reactiongifs.me/wp-content/uploads/2014/10/tyrion-lannister-eyebrows-game-of-thrones.gif",
      comment: " Wowzers!"}
    ,{
      image: "http://www.reactiongifs.us/wp-content/uploads/2013/03/GoT_joffrey_approves.gif",
      comment:  " Not bad."}
    ,{
      image: "http://imagesmtv-a.akamaihd.net/uri/mgid:file:http:shared:mtv.com/news/wp-content/uploads/2015/04/eyeroll-1429202565.gif",
      comment: " You disappoint me child."}
    ,{
      image: "http://imagesmtv-a.akamaihd.net/uri/mgid:file:http:shared:mtv.com/news/wp-content/uploads/2015/06/seeaspider-1433860136.gif",
      comment: " Valar Morghulis."}
    ];


// continue with next question or end
var start = function(questionNumber) {
      $('h2').hide().fadeIn(400);

      if(questionNumber !== allQuestions.length){
          question(questionNumber);
      }else{
          end();
      }
};

// show question and possible answers
function question(questionNum) {
      $("h2").text(allQuestions[questionNum].question);

      $.each(allQuestions[questionNum].choices, function(i, answers){
         $("#" + i).html(answers);
      });
};

function end() {
  finalImage();
  $("ul").hide();
  $("h2").text("You scored " + totalCorrect + " out of " + allQuestions.length + ". " + result[optionFinal].comment);
  $("#image").html('<img src=' + result[optionFinal].image + ' alt="">').fadeIn(1000);
  $("#try-again-container").show();
  restart();
};

// result image accourding to correct answers
function finalImage() {
  if(totalCorrect < allQuestions.length && totalCorrect >= (allQuestions.length*.7)){
            optionFinal = 1;
    }else if(totalCorrect <= (allQuestions.length*.6) && totalCorrect >= (allQuestions.length*.2)){
          optionFinal = 2;
    }else if(totalCorrect !== allQuestions.length){
          optionFinal = 3;
    }
}

function restart(){
  $("#try-again").click(function(){
    questionNumber = 0,
    totalCorrect = 0,
    optionFinal = 0;

    start(questionNumber);
    $("#image").hide();
    $("#try-again-container").hide();
    $("ul").fadeIn(400);
  });
} 

function answerCheck(userAnswer) {
     var correctAnswer = allQuestions[questionNumber].answer;

     if (userAnswer === correctAnswer) {
         $("#" + userAnswer).addClass("correctStyle");
         totalCorrect++;
     }else{
        $("#" + userAnswer).addClass("incorrectStyle");
     }
};






            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console