Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div id="container">
	<header>
		<h3>Quiz</h3>
		<p>Test Your Knowledge</p>
	</header>
	<section>
		<form name="jsQuiz" onsubmit="return submitAnswers()">
			<h3>1. How many days are there in a calendar year?</h3>
			<input type="radio" name="q1" value="a" id="q1a">a. 295<br>
			<input type="radio" name="q1" value="b" id="q1b">b. 395<br>
			<input type="radio" name="q1" value="c" id="q1c">c. 365<br>
			<input type="radio" name="q1" value="d" id="q1d">d. 360<br>
			
			<h3>2. What year was the Northridge Earthquake?</h3>
			<input type="radio" name="q2" value="a" id="q2a">a. 1991<br>
			<input type="radio" name="q2" value="b" id="q2b">b. 1992<br>
			<input type="radio" name="q2" value="c" id="q2c">c. 1993<br>
			<input type="radio" name="q2" value="d" id="q2d">d. 1994<br>
			
			<h3>3. Name an exotic fighting fish.</h3>
			<input type="radio" name="q3" value="a" id="q3a">a. White Sturgeon<br>
			<input type="radio" name="q3" value="b" id="q3b">b. Stingray<br>
			<input type="radio" name="q3" value="c" id="q3c">c. Japanese Fighting Fish<br>
			<input type="radio" name="q3" value="d" id="q3d">d. Sailfish<br>
			
			<h3>4. What are summers like in Washington DC?</h3>
			<input type="radio" name="q4" value="a" id="q4a">a. Arid<br>
			<input type="radio" name="q4" value="b" id="q4b">b. Humid with Thunderstorms<br>
			<input type="radio" name="q4" value="c" id="q4c">c. Freezing<br>
			<input type="radio" name="q4" value="d" id="q4d">d. Beach Weather<br>
			
			<h3>5. Name a modern web technology.</h3>
			<input type="radio" name="q5" value="a" id="q5a">a. Cold Fusion<br>
			<input type="radio" name="q5" value="b" id="q5b">b. Flash<br>
			<input type="radio" name="q5" value="c" id="q5c">c. Angular<br>
			<input type="radio" name="q5" value="d" id="q5d">d. Quark Express<br><br>
			<input type="submit" value="submit">
		</form>
		<div id="test-results"></div>
	</section>
</div>
	
	<footer>JavaScript Quiz Tutorial</footer>
              
            
!

CSS

              
                input {
	margin-right: 10px;
	margin-bottom: 10px;
}
#container, footer {
	background-color: lightgrey;
	max-width: 1200px;
	margin: 15px auto;
	padding: 15px;
	border-radius: 6px;
}
h3 {
	margin: 15px 0;
}
#test-results {
	background-color: darkgrey;
    color: white;
    border-radius: 6px;
    margin: 20px 0;
    border: 1px solid black;
	padding: 10px;
	display: none;
}
input {
	border-radius: 6px;
}

              
            
!

JS

              
                function submitAnswers(){
	var total = 5,
		score = 0,
		answers = ["c", "d", "c", "b", "c"],
		results = document.getElementById('test-results'),
		q1 = document.forms["jsQuiz"]["q1"].value,
		q2 = document.forms["jsQuiz"]["q2"].value,
		q3 = document.forms["jsQuiz"]["q3"].value,
		q4 = document.forms["jsQuiz"]["q4"].value,
		q5 = document.forms["jsQuiz"]["q5"].value;
			
		// validation
		for(var i = 1; i <= total; i++) {
			if(eval('q' + i) == null || eval('q' + i) == '') {
				alert("Please answer question " + i);
				return false;
			}
		}
	
		// increment score
		for(var i = 1; i <= total; i++) {
			if(eval('q' + i) == answers[i - 1]) {
				score++;
			}
		}
	
		// display results
		results.innerHTML = "You scored <span> " + score + " </span> out of " + total;
		results.style.display = "block";
;		return false;
		
}
              
            
!
999px

Console