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 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.
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.
<!-- Fonts -->
<link href='https://fonts.googleapis.com/css?family=Righteous' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<!-- App - Main Body -->
<!-- App - Menu -->
<div class="container appFrame startScreen text-center">
<h1 class="text-center">Evil Simon</h1>
<h2 class="text-center">You better do as I say!</h2>
<button class="btn playNow">Play Now!</button>
<h4 class="text-center">Game Mode</h4>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<h5><a target="_blank" href="http://www.freepik.com/free-vector/comic-cartoon-character_758722.htm">Evil Simon Character - Designed by Freepik</a></h5>
</div>
<!-- App - Gaming Board -->
<div class="container appFrame gameBoard text-center">
<div class="scoreCircle">
<p class="text-center scoreCounter">0</p>
<button class="btn stopBtn">Stop</button>
</div>
<div class="row">
<button class="playField col-md-6 col-xs-6" id="G">
</button>
<button class="playField col-md-6 col-xs-6" id="R">
</button>
</div>
<div class="row">
<button class="playField col-md-6 col-xs-6" id="Y">
</button>
<button class="playField col-md-6 col-xs-6" id="B">
</button>
</div>
</div>
<!-- App - Result Page -->
<div class="container appFrame resultScreen text-center">
<h1 class="text-center">Results</h1>
<h1 class="text-center scoreResults"></h1>
<h3 class="text-center">Think you can do better?</h3>
<button class="btn playAgain">Play Again!</button>
</div>
<!-- App - Winner Page -->
<div class="container appFrame winnerScreen text-center">
<h1 class="text-center">Winner !</h1>
<h3 class="text-center">Think you can beat me again?</h3>
<button class="btn playAgain">I dare you!</button>
<h6><a target="_blank" href="http://www.freepik.com/free-vector/comic-cartoon-character_758722.htm">Icon made by Freepik from www.flaticon.com</a></h6>
</div>
body {
background-color: #324E5C;
}
h1 {
margin-top: 30px;
font-family: 'Righteous', cursive;
font-size: 55px;
}
h2 {
font-family: 'Architects Daughter', cursive;
font-size: 25px;
font-weight: bold;
margin-top: -5px;
background-color: rgba(0, 0, 0, 0.8);
border-radius: 15px;
color: white;
}
h3 {
font-family: 'Montserrat', sans-serif;
margin-top: 110%;
}
h4 {
font-family: 'Montserrat', sans-serif;
font-weight: bold;
margin-top: 18px;
}
h5 {
font-size: 6px;
margin-top: 25px;
margin-left: 134px;
}
h6 {
font-size: 7px;
margin-top: 20px;
margin-left: 104px;
}
p {
font-family: 'Montserrat', sans-serif;
font-size: 45px;
font-weight: bold;
margin-top: 6px;
}
.appFrame {
background-color: #D3D3D3;
width: 320px;
height: 580px;
margin-top: 10%;
border: 10px solid #333238;
border-radius: 10px;
}
.playField {
width: 140px;
height: 275px;
border: 4px solid black;
margin-left: 6px;
margin-top: 2px;
border-radius: 12px;
}
.gameBoard {
display: none;
}
.resultScreen {
display: none;
}
.scoreResults {
font-size: 80px;
margin-bottom: -100px;
}
.startScreen {
background-image: url("https://dl.dropboxusercontent.com/s/c2cppjlpg25f0i0/SimonChar.png?dl=0");
background-size: cover;
}
.winnerScreen {
background-image: url("https://www.dropbox.com/s/db80ujrecqcbfjj/winnerIcon.png?raw=1");
background-size: 35% 30%;
background-repeat: no-repeat;
background-position: 50% 40%;
display: none;
}
#G {
background-color: #B9BD6F;
}
#R {
background-color: #F73955;
}
#Y {
background-color: #EEC84C;
}
#B {
background-color: #467B87;
}
.scoreCircle {
background-color: #D3D3D3;
border: 5px solid black;
border-radius: 50%;
width: 120px;
height: 120px;
z-index: 1;
margin-top: 220px;
margin-left: 75px;
position: absolute;
}
.playAgain {
font-family: 'Montserrat', sans-serif;
font-size: 25px;
font-weight: bold;
width: 170px;
height: 80px;
border: 3px solid black;
border-radius: 15px;
background-color: #38A3AC;
}
.playNow {
font-family: 'Montserrat', sans-serif;
font-size: 25px;
font-weight: bold;
width: 170px;
height: 80px;
border: 3px solid black;
border-radius: 15px;
background-color: #38A3AC;
margin-top: 85%;
}
.stopBtn {
font-weight: bold;
height: 33px;
width: 59px;
border-radius: 14px;
margin-top: -22px;
border: 2px solid black;
background-color: #38A3AC;
}
.onoffswitch {
position: relative;
width: 130px;
margin-left: auto;
margin-right: auto;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 10px;
}
.onoffswitch-inner {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before,
.onoffswitch-inner:after {
display: block;
float: left;
width: 50%;
height: 30px;
padding: 0;
line-height: 30px;
font-size: 14px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "NORMAL";
padding-left: 10px;
background-color: #38A3AC;
color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "HERO MODE";
padding-right: 10px;
background-color: #EB6161;
color: #FAF0F0;
text-align: right;
}
.onoffswitch-switch {
display: block;
width: 18px;
margin: 6px;
background: #FFFFFF;
position: absolute;
top: 0;
bottom: 0;
right: 96px;
border: 2px solid #999999;
border-radius: 10px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
$(document).ready(function() {
// Initialize Game Settings
var sequence = [];
var score = 0;
var gameTempo = 1100; // Lowest tempo available
var gameMode = "Normal";
var thisRound = [];
var playFieldId = "";
const soundFiles = [
["https://crossorigin.me/https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"], // Green
["https://crossorigin.me/https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"], // Red
["https://crossorigin.me/https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"], // Yellow
["https://crossorigin.me/https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"], // Blue
["https://crossorigin.me/http://freesound.org/data/previews/142/142608_1840739-lq.mp3"] // Wrong
];
// Function building the sequence for current game.
// Abbrv. : G - Green. R - Red. Y - Yellow. B - Blue.
var getSequence = function(sequenceSize) {
for (var i = 0; i < sequenceSize; i++) {
var rand = Math.random();
if (rand < 0.25) {
sequence.push("G");
} else if (rand >= 0.25 && rand < 0.50) {
sequence.push("R");
} else if (rand >= 0.50 && rand < 0.75) {
sequence.push("Y");
} else {
sequence.push("B");
}
}
};
// Function defining the game speed. Values in millisecond.
var getTempo = function(score) {
if (score < 5) {
gameTempo = 200;
} else if (score >= 5 && score < 9) {
gameTempo = 350;
} else if (score >= 9 && score < 13) {
gameTempo = 830;
} else {
gameTempo = 740;
}
};
// Function playing the sound files. Using Howler library.
// Also, responsible for highlighting tile colors.
var animateField = function(index) {
var whichSound;
if (index === "G") {
whichSound = soundFiles[0];
$("#G").animate({
opacity: 0.2
}, 200).animate({
opacity: 1
}, 100);
} else if (index === "R") {
whichSound = soundFiles[1];
$("#R").animate({
opacity: 0.2
}, 200).animate({
opacity: 1
}, 100);
} else if (index === "Y") {
whichSound = soundFiles[2];
$("#Y").animate({
opacity: 0.2
}, 200).animate({
opacity: 1
}, 100);
} else if (index === "B") {
whichSound = soundFiles[3];
$("#B").animate({
opacity: 0.2
}, 200).animate({
opacity: 1
}, 100);
} else if (index === "Wrong") {
// Sound file for wrong moves.
whichSound = soundFiles[4];
}
var soundUsingHowler = new Howl({
src: whichSound
});
soundUsingHowler.play();
};
// Game Mode Button functionality
$(".onoffswitch-label").on("click", function() {
if (gameMode == "Normal") {
gameMode = "Strict";
} else {
gameMode = "Normal";
}
});
// Function timing the animation sequence according to tempo.
var timedAnimations = function(index) {
getTempo();
$(".scoreCounter").text(score);
setTimeout(function() {
animateField(sequence[index]);
}, index * gameTempo);
};
// Function responsible for the animations.
var playSequence = function() {
for (var j = 0; j <= score; j++) {
thisRound.push(sequence[j]);
timedAnimations(j);
playFieldId = "";
}
};
var clickOn = false; // Credit to Ken Haduch @khaduch for solving a crucial bug at this function.
// Function that takes player input
var getPlayerSequence = function() {
// Play sequence up to the score point.
playSequence();
if (clickOn === false) {
$('.playField').click(function() {
// Animate user-pressed playing fields.
playFieldId = $(this).attr('id');
// If the last one is correct, proceed to next round.
// Intoduces 1.5 second delay between rounds.
if (playFieldId == thisRound[0] && thisRound.length === 1) {
score += 1;
// At score 20, Winning game condition.
if (score == 20) {
$(".gameBoard").css("display", "none");
$(".winnerScreen").css("display", "block");
Howler.mute(true);
}
animateField(playFieldId);
setTimeout(function() {
thisRound.shift();
playFieldId = " ";
playSequence();
}, gameTempo);
// Keep pushing till the last one.
} else if (playFieldId == thisRound[0] && thisRound.length > 1) {
animateField(playFieldId);
thisRound.shift();
playFieldId = " ";
} else {
// Wrong input.
animateField("Wrong");
if (gameMode == "Strict") {
// Failing at strict mode ends the game.
$(".gameBoard").css("display", "none");
$(".resultScreen").css("display", "block");
$(".scoreResults").text(score);
} else {
// Failing at Normal mode plays the sequence again.
setTimeout(function() {
thisRound = [];
playSequence();
}, 500);
}
}
});
}
clickOn = true;
};
// Button functionality
$(".btn").on("click", function() {
var whichButton = $(this).text();
if (whichButton === "Play Now!") {
$(".startScreen").css("display", "none");
$(".gameBoard").css("display", "block");
// Reset Game Settings.
score = 0;
thisRound = [];
sequence = [];
Howler.mute(false);
// Initiate new game.
getSequence(20);
getPlayerSequence();
} else if (whichButton === "Play Again!" || whichButton === "I dare you!") {
$(".resultScreen").css("display", "none");
$(".winnerScreen").css("display", "none");
$(".startScreen").css("display", "block");
} else if (whichButton === "Stop") {
Howler.mute(true);
$(".gameBoard").css("display", "none");
$(".resultScreen").css("display", "block");
$(".scoreResults").text(score);
}
});
});
Also see: Tab Triggers