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>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Quizr - Quizzes For All!</title>


<link rel="stylesheet" type="text/css" href="styles/styles.css">
<script src="https://cdn.firebase.com/js/client/2.2.1/firebase.js"></script>

</head>

<body>

<a id="addQ">Add Question</a>

<div class="points_container">
	<h1 class="points">Points: 0/0</h1>
</div>
 
 <div class="main-container">   
    <div class="container">
    
        <h1 class="title"></h1>
        
        <form id="quiz_form">
            <div class="a_container">
                <label for="0" id="a1"></label>
                <input type="radio" name="answers" id="0"><br/>
            </div>
            
            <div class="a_container">   
                <input type="radio" name="answers" id="1">
                <label for="1" id="a2"></label><br/>
            </div>
            
            <div class="a_container">    
                <label for="2" id="a3"></label>
                <input type="radio" name="answers" id="2"><br/>
            </div>
            
            <div class="a_container">    
                <label for="3" id="a4"></label>
                <input type="radio" name="answers" id="3"><br/>
            </div>
                
        </form>
        <div class="buttons">
            <a class="btn" id="check">Check</a>
            <a class="btn" id="next">Next</a>
            <a class="btn" id="retry">Retry</a>
            <a class="btn" id="finish">Finish</a>
        </div>
    
    </div>
</div>

<div class="modal correct">Correct!</div>
<div class="modal incorrect">Incorrect!</div>
<div class="modal none">None Selected!</div>
<div class="modal results"></div>
<a class="close">close [x]</a>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="scripts/app.js"></script>
<script src="scripts/questions.js"></script>
</body>
</html>
            
          
!
            
              @charset "UTF-8";
/* MAIN */

body {
	background-color: #BCCECA;
	z-index: -1;	
}

.container {
	margin: 1em;
	margin-top: 4em;	
	background-color: rgba(255,252,252,0.64);
	border-radius: 30px;
	padding: 0 0 30px 0;
}

.title {
	margin: 0 auto;
	max-width: 100%;
	text-align: center;
	font-size: 3em;
	padding: 10px;
	color: #F33A3D;
	border-bottom: 2px solid #4298B7;
}

label {
	font-size: 30px;
	cursor: pointer;	
	max-width: 100%;
}

.buttons {
	max-width: 100%;
	text-align: right;	
	margin-top: 30px;
}

.btn {
	color: #16A208;
	text-align: right;
	max-width: 100%;	
	font-size: 20px;
	background-color: white;
	padding: 5px;
	border-radius: 10px;
	cursor: pointer;
	margin-right: 20px;	
	display: none;
}

#check {
	display: inline;
}

.btn:hover {
	background-color: #84FB9D;
	color: #115100;	
}

.points{
	max-width: 100%;
	text-align: right;
	padding: 10px;
	background-color: rgba(255,255,255,0.64);
	color: #4298B7;
	font-size: 2em;
}

.a_container {
	border-bottom: 1px solid #D6D6D6;
	height: 2.75em;
	max-width: 100%;
	background-color: white;
	cursor: pointer;
	text-align: center;
}

.a_container:hover {
	border: 2px solid #317AF0;	
}

input[type="radio"] {
	display: none;	
}

.selected {
	background-color: #B7C8FB;	
}

.good {
	background-color: #84FB9D;
}

.bad {
	background-color: #FB888A;	
}

.modal {
	font-size: 60px;
	text-align: center;
	position: fixed;
	height: 60px;
	width: 300px;
	background-color: rgba(0,0,0,0.76);
	top: 50%;
	left: 50%;
	margin-left: -150px;
	margin-top: -40px;
	padding: 10px 0;
	z-index: 1001;
	border-radius: 20px;
	display: none;
}

.correct {
	color: #A0FFCA;
}

.incorrect {
	color: #FFCACB;
}

.none {
	font-size: 40px;
	color: white;	
}

.results {
	font-size: 60px;
	text-align: center;
	position: fixed;
	height: 100vh;
	width: 100%;
	background-color: rgba(0,0,0,0.76);
	top: 0;
	left: 0;
	margin-left: 0;
	margin-top: 0;
	padding: 10px 0;
	padding-top: 100px;
	border-radius: 0;
	display: none;
	color: white;
}

.close {
	position: fixed;
	top: 5%;
	right: 5%;
	color: #DC585A;
	font-size: 20px;	
	cursor: pointer;
	z-index: 1002;
	display: none;
}

#addQ {
	height: 15px;
	width: 120px;
	font-size: 15px;
	background-color: #F33A3D;
	position: fixed;	
	color: white;
	text-align: center;
	border-radius: 10px;
	padding: 5px 0;
	cursor: pointer;
	top: 15px;
	left: 5px;
}

#addQ:hover {
	background-color: #D73134;	
}


/* MEDIA QUERIES */


@media (min-width: 850px) {
	#addQ {
		top: 15px;	
	}
	
	.a_container {
		padding: 1em 0;	
	}
	
	label {
		font-size: 50px;
	}
	
	.container {
		max-width: 75%;	
		margin: 0 auto;
		margin-top: 4em;
	}
}

@media (max-width: 700px) {
	#addQ {
		top: 15px;	
	}
	.title {
		font-size: 2.5em;
	}
}

@media (max-width: 400px) {
	#addQ {
		top: 5px;	
	}
	.title {
		font-size: 24px;
		background-color: rgba(255,252,252,0.64);
		
	}
	
	label {
		font-size: 24px;	
	}
	
	.points {
		font-size: 18px;	
		padding: 5px;
		
	}
	
	.container {
		padding: 0;	
		height: 0;
		margin: 0;
		margin-top: 0;
	}

	.buttons {
		margin-top: 20px;
	}

	.btn {
		font-size: 24px;	
		
	}
	
	.a_container {
		height: 2em;	
		padding: 1em 0;
	}
		
}

            
          
!
            
              // JavaScript Document
$(function() {

  //QUESTIONS
  var allQuestions = [{
    question: "What is Dustin's favorite color?",
    choices: ["Red", "Green", "Purple", "Yellow"],
    answer: 3
  }, {
    question: "What is Dustin's favorite movie out of these options?",
    choices: ["Little House on the Prairie", "Land Before Time", "Big Hero 6", "Harry Potter"],
    answer: 2
  }, {
    question: "What is Dustin's favorite time of year?",
    choices: ["Summer", "Spring", "April 19th", "Christmas"],
    answer: 0
  }, {
    question: "What is Dustin's favorite passtime out of these options?",
    choices: ["Eatin' Foods", "Music Playin'", "TV Watchin'", "Bein' Praised"],
    answer: 1
  }, {
    question: "What is Dustin's deepest desire?",
    choices: ["To Be the Best", "To Help Others", "To Catch 'em All", "To Save the World"],
    answer: 1
  }, {
    question: "How do you catch a Dustin?",
    choices: ["Put Cheese in a Mouse Trap", "With a Pokeball", "With Your Hands", "You Need Kryptonite"],
    answer: 3
  }, {
    question: "For what reason would Dustin eat dairy?",
    choices: ["Cheesecake", "A Young Moose is in Peril", "April 19th", "Peer Pressure"],
    answer: 0
  }, {
    question: "What is Dustin's favorite passtime out of these options?",
    choices: ["Practicing Chinese Characters", "Hanging With Homies", "Dancing", "Working Out The Good Ol' Traps"],
    answer: 1
  }, {
    question: "How do you feel like you know Dustin?",
    choices: ["I don't.", "Better Than I Should", "So, So Good. I Think.", "This Was A Waste of Time"],
    answer: 3
  }];

  /*----------BUTTON AND VARIABLE SETUP----------*/
  var i = 0;
  var numCorrect = 0;

  $('#next').hide();
  $('#finish').hide();
  $('.modal').hide();
  $('.close').hide();

  /*----------FUNCTIONS SETUP----------*/

  function newQuestion(i) {
    $('.title').text(allQuestions[i].question);
    $('#a1').text(allQuestions[i].choices[0]);
    $('#a2').text(allQuestions[i].choices[1]);
    $('#a3').text(allQuestions[i].choices[2]);
    $('#a4').text(allQuestions[i].choices[3]);
  }

  function btnSwitch(btn) {
    $('#' + btn).toggle();
    $('#check').toggle();
  }

  function writePoints(numCorrect) {
    $('.points').text('Points: ' + numCorrect + '/' + allQuestions.length);
  }

  function initPoints() {
    $('.points').text('Points: ' + 0 + '/' + allQuestions.length);
  }

  function correctAnswer() {
    console.log("Correct");
    $('input[type=radio]:checked').parent().addClass("good");
    $('.bad').removeClass('bad');
    numCorrect++;
    writePoints(numCorrect);
    $('.correct').fadeIn(500).fadeOut(2000);
    return numCorrect;
  }

  function incorrectAnswer() {
    console.log("Incorrect");
    $('input[type=radio]:checked').parent().addClass("bad");
    writePoints(numCorrect);
    $('.incorrect').fadeIn(500).fadeOut(2000);
  }

  function nextQuestion() {
    $('.selected').removeClass('selected');
    $('.good').removeClass('good');
    $('.bad').removeClass('bad');
    $('input[name="answers"]').prop('checked', "false");
    newQuestion(i);
    btnSwitch('next');
    return i++;
  }

  function deselectAll() {
    $('input').prop('checked', false);
  }

  function showCorrect(i) {
    $('#a' + (allQuestions[i - 1].answer + 1)).parent().addClass("good");
  }

  /*--Initialize setup with first question and 0 points out of TOTAL--*/
  newQuestion(i);
  i++;
  initPoints();

  /*-----BUTTONS CLICK FUNCTIONS-----*/
  $('#check').on('click', function() {
    if (i >= allQuestions.length && $('input[type=radio]:checked').attr('id') == allQuestions[i - 1].answer) {
      console.log("Finish");
      btnSwitch('finish');
      $('#retry').show();
      correctAnswer();
    } else if (i >= allQuestions.length && $('input[type=radio]:checked').attr('id') !== allQuestions[i - 1].answer) {
      console.log("Finish");
      showCorrect(i);
      btnSwitch('finish');
      $('#retry').show();
      incorrectAnswer();
    } else if ($('input[type=radio]:checked').attr('id') == allQuestions[i - 1].answer) {
      correctAnswer();
      btnSwitch('next');
    } else if ($('input[type=radio]:checked').attr('id') !== allQuestions[i - 1].answer && $('input').is(':checked')) {
      incorrectAnswer();
      showCorrect(i);
      btnSwitch('next');

    } else {
      console.log("None selected");
      $('.none').fadeIn(500).fadeOut(2000);
    }
  }); //end check

  $('#next').on('click', function() {
    nextQuestion();
    deselectAll();
  }); //end next

  //ANSWERS
  $('input[name="answers"]').on('change', function() {
    $('.selected').removeClass('selected');
    $(this).parent().toggleClass('selected');
  });

  $('.a_container').on('click', function() {
    $('.selected').removeClass('selected');
    $(this).toggleClass('selected');
    $(this).children('input[type="radio"]').prop('checked', 'true');
  });

  //BIG FINISH

  $('#finish').on('click', function() {
    console.log('You got ' + ((numCorrect / allQuestions.length) * 100) + '% of the questions right!');
    var results = $('.results');
    results.text('You got ' + (Math.round(numCorrect / allQuestions.length * 100)) + '% of the questions right!');
    results.fadeIn();
    $('.close').fadeIn();
  });

  //CLOSE RESULTS

  function closeResults() {
    $('.results').fadeOut();
    $('.close').fadeOut();
  }

  $('.close').on('click', function() {
    closeResults();
  });

  $('.results').on('click', function() {
    closeResults();
  });

  //RETRY

  $('#retry').on('click', function() {
    console.log("unable to retry...");
    location.reload();
  });

  //ADD QUESTION

  $('#addQ').on('click', function() {
    //Show Form for AddQuestion
    //Before Questions can be Added
    $(this).text('Cannot in Beta').css('background-color', '#ccc');
  });

}); //end ready
            
          
!
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