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.
<div id="frame">
<div id="4canvas">
<div id="controls">
<h1 class="brand">Simon<sup>®</sup></h1>
<div>
<!-- Start Button (Bootstrap) -->
<button type="submit" class="btn btn-success btn-lg disabled" data-toggle="button" aria-pressed="false" autocomplete="off">
<span class="glyphicon glyphicon-play"></span>
</button>
<!-- End -->
<!-- LCD Display -->
<div class="display inline">
<h1 id="counter" class="count led-off">00</h1>
</div>
<!-- End -->
<!-- Strict Mode Button (Bootstrap) -->
<button type="submit" class="btn btn-danger btn-lg disabled" data-toggle="button" aria-pressed="false" autocomplete="off">
<span class="glyphicon glyphicon-flash"></span>
</button>
<!--End of Strict Mode Button-->
</div>
<!-- Rounded On/Off switch -->
<div class="onoffswitch" id="onoff">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<div>
<canvas id="green">
<audio id="audio1" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"></audio>
</canvas>
<canvas id="red">
<audio id="audio2" src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"></audio>
</canvas>
</div>
<div>
<canvas id="yellow">
<audio id="audio3" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"></audio>
</canvas>
<canvas id="blue">
<audio id="audio4" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"></audio>
</canvas>
</div>
</div>
</div>
/*Generic CSS (Aplies to all devices)*/
@import 'https://fonts.googleapis.com/css?family=Alfa+Slab+One|Black+Ops+One';
body {
/*
CSS3 Patterns Gallery. (Carbon)
by Atle Mo (design), Sébastien Grosjean (code)
*/
background: linear-gradient(27deg, #151515 5px, transparent 5px) 0 5px, linear-gradient(207deg, #151515 5px, transparent 5px) 10px 0, linear-gradient(27deg, #222 5px, transparent 5px) 0 10px, linear-gradient(207deg, #222 5px, transparent 5px) 10px 5px, linear-gradient(90deg, #1b1b1b 10px, transparent 10px), linear-gradient(#1d1d1d 36%, #1a1a1a 25%, #1a1a1a 50%, transparent 50%, transparent 75%, #242424 75%, #242424);
background-color: #131313;
background-size: 20px 20px;
}
.inline {
display: inline-block;
}
/*Wrapper*/
#frame {
background-color: #333333;
height:414px;
width: 414px;
margin: -207px 0 0 -207px;
position: absolute;
top: 50%;
left: 50%;
padding: 5px;
border-radius: 50%;
}
/*End*/
#controls {
width: 250px;
height: 250px;
position: absolute;
margin: -125px 0 0 -125px;
top: 50%; left:50%;
border: 4px solid #333333;
border-radius: 50%;
background: white;
text-align: center;
}
/*Simon title inside white circle*/
.brand {
font-family: 'Alfa Slab One', cursive;
color: #222;
font-size: 4rem;
margin-top: 15%;
text-align: center;
}
/*End*/
/* Display/Counter */
.display {
width: 70px;
position: relative;
margin: 7px 15px;
text-align: center;
}
.count {
height: 60px;
font-family: 'Black Ops One', monospace;
color: #DC0D29;
padding-top: 10px;
background-color: #32050C;
position: relative;
border: 4px solid #222;
border-radius: 10px;
margin: 0 auto;
}
.led-off {
font-size:3rem;
color: #430710;
vertical-align: middle;
}
.led-on {
font-size:3rem;
color: #ff0000;
vertical-align: middle;
}
.label {
color: #222;
font-family: 'Oswald', Arial, sans;
font-size: 0.7em;
margin-top: 5px;
text-align: center;
}
.full-red {
background-color: #FC0102;
}
.clickable {
pointer-events: auto;
cursor: pointer;
}
.led {
width: 6px;
height: 6px;
background-color: #32050C;
border-radius: 100%;
position: absolute;
left: 0;
right: 0;
margin: auto;
border: 2px solid #222;
top: -18px;
}
.sw-slot {
height: 20px;
width: 40px;
background-color: #222;
position: relative;
top: 5px;
border-radius: 2px;
cursor: pointer;
}
/*End*/
/*Giving buttons a rounded shape*/
.btn {
border-radius: 40%;
}
/* Power On/Off switch*/
/*Inspiration thanks to: proto.io/freebies/onoff/*/
.onoffswitch {
position: relative;
width: 70px;
user-select:none;
margin: 30px auto;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 20px;
}
.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: 25px;
padding: 0;
line-height: 25px;
font-size: 12px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 15px;
background-color: #34A7C1;
color: #FFFFFF;
text-align: left;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE;
color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block;
width: 30px;
margin: -2.5px;
background: #FFFFFF;
position: absolute;
top: 0;
bottom: 0;
right: 41px;
border: 2px solid #999999;
border-radius: 20px;
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;
}
/*End of Power On/Off Switch*/
/*Canvas color and shape*/
canvas {
width: 200px;
height:200px;
}
#green {
background-color: #27ae60;
border-top-left-radius: 100%
}
.green-grad {
background: radial-gradient(circle, white, #27ae60);
border-top-left-radius: 100%
}
#red {
background-color: #e74c3c;
border-top-right-radius: 100%;
}
.red-grad {
background: radial-gradient(circle, white, #e74c3c);
border-top-right-radius: 100%;
}
#yellow {
background-color: #f1c40f;
border-bottom-left-radius: 100%;
}
.yellow-grad {
background: radial-gradient(circle, white, #f1c40f);
border-bottom-left-radius: 100%;
}
#blue {
background-color: #3498db;
border-bottom-right-radius: 100%;
}
.blue-grad {
background: radial-gradient(circle, white, #3498db);
border-bottom-right-radius: 100%;
}
/* End */
$(document).ready(function() {
// Array of random colors generated
// at the begining of each game.
var randColors = [],
// Actual round.
round,
numberOfRounds = 5,
// clickRound: How many clicks/round.
clickRound,
// This is the time in milliseconds
// that each pad is illuminated.
// Set as a global variable so
// it can be easily changed
timeForEachPad = 500,
// This variable will be used to check
// if the game is powered on or off
// OFF --> 0 and ON --> 1
powerCheck = 0,
// These four objects represent the four pads
// with their colors, gradient colors
// and audio generated on click and each
// of the colored canvas where the user should click
greenPad = {
color: "green",
gradColor: "green-grad",
audio: document.getElementById("audio1"),
item: "greenCanvas"
},
redPad = {
color: "red",
gradColor: "red-grad",
audio: document.getElementById("audio2"),
item: "redCanvas"
},
yellowPad = {
color: "yellow",
gradColor: "yellow-grad",
audio: document.getElementById("audio3"),
item: "yellowCanvas"
},
bluePad = {
color: "blue",
gradColor: "blue-grad",
audio: document.getElementById("audio4"),
item: "blueCanvas"
};
// This function will illuminate
// a pad with the color passed
// as the parameter and generate
// a corresponding sound for it.
function illuminate(col) {
if (col === "green") {
console.log("Color was green");
greenPad.audio.play();
$("#green").addClass("green-grad");
setTimeout(function() {
$("#green").removeClass("green-grad");
}, timeForEachPad);
}
if (col === "blue") {
console.log("Color was blue");
bluePad.audio.play();
$("#blue").addClass("blue-grad");
setTimeout(function() {
$("#blue").removeClass("blue-grad");
}, timeForEachPad);
}
if (col === "red") {
console.log("Color was red");
redPad.audio.play();
$("#red").addClass("red-grad");
setTimeout(function() {
$("#red").removeClass("red-grad");
}, timeForEachPad);
}
if (col === "yellow") {
console.log("Color was yellow");
yellowPad.audio.play();
$("#yellow").addClass("yellow-grad");
setTimeout(function() {
$("#yellow").removeClass("yellow-grad");
}, timeForEachPad);
}
}
// Generate a random array of colors
function randomColorsGenerator() {
while (randColors.length < numberOfRounds) {
// If number is between
if (Math.random()*4 < 1) {
randColors.push("red");
} else if (Math.random()*4 >= 1 &&
Math.random()*4 < 2) {
randColors.push("blue");
} else if (Math.random()*4 >= 2 &&
Math.random() * 4 < 3) {
randColors.push("yellow");
} else {
randColors.push("green");
}
}
console.log("Actual color sequence is (" + randColors + ")");
}
// If the user made a mistake
// this sound will reproduce.
function errorSound() {
greenPad.audio.play();
redPad.audio.play();
yellowPad.audio.play();
bluePad.audio.play();
}
// Reproduce just one round
function reproduceRound(round) {
// Set round number in display
$("#counter").text(round);
// Delay between rounds (in milliseconds)
var timeBetweenRounds = 1000;
for (var i = 0; i < round; i++) {
setTimeout(illuminate, (i + 1) * timeBetweenRounds, randColors[i]);
}
}
function normal() {
round = 1;
// New random array of colors
randColors = [];
randomColorsGenerator();
//Press Play to begin
reproduceRound(round);
clickRound = 0;
// Register clicks
$("canvas").click(function(event) {
//for(var i = 0; i<ronda; i++){
illuminate(event.target.id);
// Validate Clicks
// If the user clicked in the right place...
if (randColors[clickRound] == event.target.id) {
clickRound++;
console.log("Good Job!");
console.log(
"Right color. Round " +
round +
". You have clicked " +
clickRound +
" times in this round"
);
// Example: in 3rd round, user must click 3 times
if (round == clickRound) {
// round + 1 (go to next round)
round++;
// Reset click counter
clickRound = 0;
console.log(
"Right color. Round = " +
round +
". Clicks in this round = " +
clickRound
);
// Reproduce next round
reproduceRound(round);
}
} else {
// User made a mistake
// Missmatch!
console.log("Wrong color ->" + event.target.id);
console.log("Start from begining");
// Error sound
greenPad.audio.play();
redPad.audio.play();
yellowPad.audio.play();
bluePad.audio.play();
// New array of colors generated
randomColorsGenerator();
// Start from round 1
// round = 1;
clickRound = 0;
$("#counter").text(round);
// Reproduce actual round
reproduceRound(round);
}
});
}
function strict() {
round = 1;
// New random array of colors
randColors = [];
randomColorsGenerator();
//Press Play to begin
//$(".btn-danger").click(function() {
reproduceRound(round);
//});
// clickRound: How many clicks per round.
clickRound = 0;
// Register clicks
$("canvas").click(function(event) {
//for(var i = 0; i<ronda; i++){
illuminate(event.target.id);
// Validate Clicks
// If the user clicked in the right place
if (randColors[clickRound] == event.target.id) {
clickRound++;
console.log("Good Job!");
console.log(
"Right color. Round " +
round +
". You have clicked " +
clickRound +
" times in this round"
);
// Example: in 3rd round, user must click 3 times
if (round == clickRound) {
// round + 1 (go to next round)
round++;
// Reset click counter
clickRound = 0;
console.log(
"Right color. Round = " +
round +
". Clicks in this round = " +
clickRound
);
// Reproduce next round
reproduceRound(round);
}
} else {
// User made a mistake
// Missmatch!
console.log("Wrong color ->" + event.target.id);
console.log("Start from begining");
// Error sound
/*
greenPad.audio.play();
redPad.audio.play();
yellowPad.audio.play();
bluePad.audio.play();
*/
errorSound()
// New array of colors generated
randomColorsGenerator();
// Start from round 1
round = 1;
clickRound = 0;
$("#counter").text(round);
// Reproduce actual round
reproduceRound(round);
}
});
}
// Power Switch config
// On click...
$(".onoffswitch-label").click(function() {
powerCheck = powerCheck + 1;
console.log("powerCheck = " + powerCheck);
// If powerCheck is an odd number, it means
// that the game has been powered on,
// and now the user can start playing.
if (powerCheck % 2 === 0) {
console.log("Turned Off");
randColors = [];
round = 1;
clickRound = 0;
// Stop sound
greenPad.audio.stop();
redPad.audio.stop();
yellowPad.audio.stop();
bluePad.audio.stop();
$(".count").removeClass("led-on");
//Add "disabled" status to normal
//mode (Play) and strict mode buttons again.
$(".btn").addClass("disabled");
$(".btn").prop("disabled", true);
$("canvas").prop("disabled", true);
$("canvas").addClass("disabled");
//Reset counter to "00"
$("#counter").text("00");
} else {
// The game has been turned on
console.log("Turned On");
randColors = [];
// Change color of led display numbers
$(".count").addClass("led-on");
// Activating buttons
$(".btn").removeClass("disabled");
$(".btn-success").click(function() {
console.log("Simon has started in Normal Mode");
normal();
});
$(".btn-danger").click(function() {
console.log("Simon has started in Strict Mode");
strict();
});
}
});
// End of onoffswitch
});
Also see: Tab Triggers