HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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");
}
};
Also see: Tab Triggers