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

              
                <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Dark javascript quiz</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://fonts.googleapis.com/css2?family=Poppins&family=Quicksand&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="dark-quiz.css">
</head>
<body>
<div class="bg-wrapper">
<div class="bg-img">
<div class="question-content">
<p1>Find out which character from Dark you are!</p1>
  <br>
<h>everything is connected</h>
<p>Pick any one word that describes you:
  <br>
<span id="keywords">#headstrong, #inexorable, #loyal, #inquisitive, #intelligent</span>
</p>
<input id="text" type="text" placeholder="Type any keyword" /> <button id="submit" type="button" onclick="result()">go</button>
<br>
<p id="answer"></p>
<div id="result-pic">
  <div class="pic-description">
   <p id="more-info"></p>
  </div>
</div>
  </div>
  </div>
<script src="dark-quiz.js"></script>
</div>
</div>
</div>
              
            
!

CSS

              
                :root {
 --bg-color: #191919;
 --faded-color: rgba(0,0,0,0.5);
 --font-color: #DDD;
 --dark: #080808;
 --yellow: #f0c54d;
 --quick:'Quicksand', sans-serif;
 --pop: 'Poppins', sans-serif;
 }
body {
 padding:0;
 margin: 0;
 background: var(--bg-color);
 font-family: var(--quick);
 user-select: none;
 overflow: hidden;
}
* {
 box-sizing: border-box;
}
h {
 font-size: 1em;
 color: white;
 text-transform: uppercase;
 letter-spacing: 3px;
 font-weight: 600;
 font-size: 1.3em;
}
h::after {
    content: "∞";
    display: block;
    text-align: center;
}
p {
 font-size: 0.8em;
 color: #DDD;
 font-family: var(--pop);
}
p1 {
    font-family: var(--quick);
    font-size: 1.6em;
    color: white;
    margin-bottom: 30px;
}
.bg-wrapper {
 height: 100vh;
 width: 100vw;
 background-image: url('https://i.imgur.com/kDTDyIe.png');
 background-repeat: no-repeat;
 background-position: center;
 background-size: cover;
}
.bg-img {
 height: 100vh;
 width: 100vw;
 position: absolute;
 background: var(--faded-color);
 display: flex;
 justify-content: center;
 align-items: center;
 transition: all .4s ease;
 -webkit-transition: all .4s ease;
 -moz-transition: all .4s ease;
}
.question-content {
 height: 90vh;
 width: 50vw;
 text-align: center;
}
#keywords {
 color: cyan;
 font-family: var(--pop);
}
input:focus, text-area:focus, select:focus, button {
 outline: none; 
 text-transform: lowercase;
}
#input-text {
 border: none;
 border-radius: 6px;
 padding: 3px;
 width: 30%;
}
#submit {
  height: 20px;
  width: 80px;
 border-radius: 5px;
  border: none;
  text-transform: uppercase;
  background: var(--dark);
 color: #add8e6;
 cursor: pointer;
}
#result {
 margin: 10px;
}
#result-pic {
    height: 53vh;
    width: 40vw;
    margin: 0 auto;
    border-radius: 6px;
    background-image: none;
     background-position: center;
     background-repeat: no-repeat;
     background-size: cover;
    transition: all .4s ease;
     z-index: -1;
    }
    .pic-description {
         position: relative;
        left:0;
         right:0;
         z-index: 1;
         background-color: darksalmon;
    }
    #more-info {
        color: black;
    }
@media screen and (max-width: 600px) {
 .question-content {
     width: 85vw;
 }
 #result-pic {
     width: 80vw;
 }
}
              
            
!

JS

              
                //displays answer in P element
var input = document.querySelector("#text");
//displays pic in result pic div
var newPic = document.querySelector("#result-pic");
//adds grayscale filter to bg img
var darken = document.querySelector(".bg-wrapper");
//adds description to pic
var picText = document.querySelector("#more-info");

function result() {
  input.value = input.value.toLowerCase();
 if (input.value === "headstrong") {
 document.getElementById("answer").innerHTML = "You got: Ulrich";
 picText.innerHTML = "You are determined to do anything";
 newPic.style.backgroundImage = "url('https://i.imgur.com/XW7Db4P.jpg')";
 darken.style.filter = "grayscale(30%)";
} else if(input.value === "inexorable") {
 document.getElementById("answer").innerHTML = "You got: Noah";
 picText.innerHTML = "You strongly believe in your principles";
 newPic.style.backgroundImage = "url('https://vignette.wikia.nocookie.net/dark-netflix/images/4/4e/Portal_%E2%80%93_Noah.jpg/revision/latest/scale-to-width-down/350?cb=20171203223020')";
 darken.style.filter = "grayscale(20%)";
} else if (input.value === "loyal") {
 document.getElementById("answer").innerHTML = "You got: Jonas";
 picText.innerHTML = "You are selfless and will do anything for your loved ones";
 newPic.style.backgroundImage = "url('https://i.imgur.com/Ve7ojGc.jpg')";
 darken.style.filter = "grayscale(20%)";
} else if (input.value === "inquisitive") {
    document.getElementById("answer").innerHTML = "You got: Charlotte";
    picText.innerHTML = "Your curiosity defines you";
    newPic.style.backgroundImage = "url('https://mcdn.wallpapersafari.com/medium/9/99/lPxBet.jpg')";
    darken.style.filter = "grayscale(20%)";
} else if (input.value === "intelligent") {
    document.getElementById("answer").innerHTML = "You got: Claudia";
    picText.innerHTML = "You have an eye for detail";
    newPic.style.backgroundImage = "url('https://i.imgur.com/rEQiNKv.jpg')";
    darken.style.filter = "grayscale(20%)";
} else {
    document.getElementById("answer").innerHTML = "Oops! seems like you haven't entered a valid word. <br> Or: check your spelling";
    newPic.style.backgroundImage = "none";
    picText.style.display = "none";
}
}
 
              
            
!
999px

Console