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. 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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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">
<head>
    <meta charset="UTF-8">
    
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

    <!-- Latest compiled and minified JavaScript w/ jQuery -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    
    <!-- Override Javascript & CSS -->
    <link rel="stylesheet" href="css/main.css" type="text/css">
    
    <link href='https://fonts.googleapis.com/css?family=Oswald:400,700,300' rel='stylesheet' type='text/css'>
    
    <title>Simple Quiz</title>
    
</head>
<body>
    <div class="row">
        <div class="container">
            <div class="col-md-12">
                <h1 class="title"><lead>The Javascript Quiz!</lead></h1>
                
                <hr>
                
                <div id="question"></div>
                
                <br>
    
                <div id="answer">
                    <div id="A"></div>
                    <div id="B"></div>
                    <div id="C"></div>
                    <div id="D"></div>
                </div>
                <br>
                <div class="answers">
                    Number Correct: <span id="correct">0</span><br>
                    Number Wrong: <span id="wrong">0</span> 
                </div>
                <div class="directions">
                    <h3>Directions</h3>
                    <p>Welcome to the Javascript Quiz!  To play the game, simply answer the questions by pressing the corresponding number key on your keyboard.  For example, 1 corresponds to choice "A", 2 corresponds to choice "B", and so on and so forth.  The game will keep track of how many questions you have right and how many questions you have wrong.  At the end of the game, you will be given the option to restart.  Have fun!</p>
                </div>
            </div>
        </div>
    </div>
    
    
    <script src="js/quiz.js"></script>
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
</body>
</html>
              
            
!

CSS

              
                body {
    background: white;
    font-family: 'Oswald', sans-serif;
}

.title {
    text-align: center;
}

#answer {
    clear: both;
}

hr {
    padding: 0;
    border: none;
    border-top: medium double #333;
    color: #333;
    text-align: center;
}

hr:after {
    content: "§";
    display: inline-block;
    position: relative;
    top: -0.7em;
    font-size: 1.5em;
    padding: 0 0.25em;
    background: white;
}

#question {
    font-weight: 700;
}

#A,
#B,
#C,
#D {
    cursor: pointer;
    width: 50px;
    margin: 10px 0;
}
              
            
!

JS

              
                var questions = [{
    text: "What tree did George Washington cut down and then lie about?",
    rightAnswer: 0,
    choices: ["None of the above", "Dogwood", "Pear", "Apple"],
    asked: false
}, {
    text: "What year did World War II end?",
    rightAnswer: 2,
    choices: ["1946", "1942", "1945", "1947"],
    asked: false
}, {
    text: "How many stars are on the United States flag?",
    rightAnswer: 0,
    choices: ["50", "51", "53", "49"],
    asked: false
}, {
    text: "How many states are in the United States?",
    rightAnswer: 0,
    choices: ["50", "51", "52", "49"],
    asked: false
}, {
    text: "Where was the shot heard around the world fired?",
    rightAnswer: 1,
    choices: ["Germany", "Austria", "United States", "Paris"],
    asked: false
}, {
    text: "What year was the Civil War?",
    rightAnswer: 1,
    choices: ["1869", "1861", "1900", "1850"],
    asked: false
}, {
    text: "What year was the atomic bomb dropped on Hiroshima and Nagasaki?",
    rightAnswer: 3,
    choices: ["1946", "1943", "1940", "1945"],
    asked: false
}, {
    text: "What is the dog's name in the show 'Family Guy'?",
    rightAnswer: 3,
    choices: ["Doug", "Barney", "Stewie", "Brian"],
    asked: false
}, {
    text: "What is the capital of Maryland?",
    rightAnswer: 0,
    choices: ["Annapolis", "Washington D.C.", "Portland", "Baltimore"],
    asked: false
}, {
    text: "What year was Woodstock held?",
    rightAnswer: 1,
    choices: ["1970", "1969", "1965", "1980"],
    asked: false
}, {
    text: "What year was John F. Kennedy assassinated?",
    rightAnswer: 2,
    choices: ["1964", "1960", "1963", "1962"],
    asked: false
}, {
    text: "What year was Richard Nixon impeached as President of the United States?",
    rightAnswer: 3,
    choices: ["1970", "1968", "1960", "None of the above"],
    asked: false
}, {
    text: "What was the name of the treaty signed after World War I?",
    rightAnswer: 2,
    choices: ["Treaty of Nuremburg", "Gestalt Treaty", "Treaty of Versailles", "Treaty of Tears"],
    asked: false
}, {
    text: "Who wrote the series 'Harry Potter'?",
    rightAnswer: 1,
    choices: ["J.R.R. Tolkein", "J.K. Rowling", "Ernest Hemingway", "Stephen King"],
    asked: false
}, {
    text: "What U.S. state is considered a peninsula?",
    rightAnswer: 1,
    choices: ["Texas", "Florida", "California", "Maine"],
    asked: false
}, {
    text: "What country is The Vatican located in?",
    rightAnswer: 2,
    choices: ["Germany", "Spain", "Italy", "Austria"],
    asked: false
}, {
    text: "What is the day 'that will live in infamy'?",
    rightAnswer: 3,
    choices: ["December 7, 1940", "December 7, 1942", "December 2, 1941", "December 7, 1941"],
    asked: false
}, {
    text: "What is the language of computers called?",
    rightAnswer: 0,
    choices: ["Binary", "C++", "JavaScript", "Machine"],
    asked: false
}, {
    text: "What was the country of origin for the ship 'The Titanic'?",
    rightAnswer: 0,
    choices: ["England", "Scotland", "Ireland", "Italy"],
    asked: false
}
                 ];

var correct = 0;
var wrong = 0;

var addCorrect = function() {
    document.getElementById("correct").innerHTML = correct + 1;
};

var addWrong = function() {
    document.getElementById("wrong").innerHTML = wrong + 1;
};

var random = Math.floor(Math.random() * questions.length);

var addNewSet = function(letter, index) {
    var randomQuestion = questions[random].text;
    var choices = questions[random].choices;
    
    document.getElementById("question").innerHTML = randomQuestion;
    
    for (var i = 0; i < 4; i++) {
        document.getElementById(letter).innerHTML = letter + ": " + questions[random].choices[index];
        console.log(questions[random].choices[i]);
    }
};


addNewSet("A", 0);
addNewSet("B", 1);
addNewSet("C", 2);
addNewSet("D", 3);
              
            
!
999px

Console