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. 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.
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.
If the stylesheet 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 CSS 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.
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.
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
<div class="container-fluid">
<div class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-2 col-xs-10" id="appContainer">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 text-center">
<h3 id="title"><b>SIMON SAYS</b></h3>
</div>
</div>
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-0"></div>
<div id="board" class="col-md-4 col-sm-4 col-xs-12">
<div id="bs1" class="boardSpot bs1"></div>
<div id="bs2" class="boardSpot bs2"></div>
<div id="settings">
<div id="roundDisplay">
<div class="round">--</div>
</div>
<div id="settingsButtons">
<button id="startBtn" class="btn btn-primary">Go</button>
<button type="button" class="btn" id="strictToggle" data-toggle="button" aria-pressed="false" autocomplete="off">Strict off</button>
<div id="powerSwitch">
<input id="powerToggle" data-toggle="toggle" type="checkbox" data-size="mini" data-onstyle="primary" data-offstyle="primary" data-on="power on" data-off="power off" />
</div>
</div>
</div>
<div id="bs3" class="boardSpot bs3"></div>
<div id="bs4" class="boardSpot bs4"></div>
</div>
<div class="col-md-4 col-sm-4 col-xs-0"></div>
</div>
</div> <!-- end appContainer -->
</div> <!-- end container-fluid -->
@media (max-width: 800px) {
#appContainer {
margin-top: 8em;
}
}
@media (min-width: 768px) and (max-width: 1600px) {
#appContainer {
margin-top: 9em;
}
}
@media (min-width: 1400px) {
#appContainer {
margin-top: 10em;
}
}
body {
font-family: 'Poppins', sans-serif;
}
#title {
font-size: 6em;
}
#board {
position:relative;
width:30em;
height:30em;
}
#powerSwitch {
margin-left: 1.8em;
margin-top: 1em;
}
#startBtn {
display:inline-block;
padding-left: 0.5em;;
padding-right: 0.5em;
}
.boardSpot {
height: 10em;;
width: 10em;
}
.boardSpot:hover {
cursor: pointer;
border:1px solid black;
}
.bs1 {
position: absolute;
left:1em;
top: 1em;
background-color: #990000;
border-top-left-radius: 100%;
}
.bs1led {
background-color: red;
}
.bs2 {
position: absolute;
left: 11em;
top: 1em;
background-color: #cccc00;
border-top-right-radius : 100%;
}
.bs2led {
background-color: yellow;
}
.bs3 {
position: absolute;
left: 1em;
top: 11em;
background-color: #000080;
border-bottom-left-radius : 100%;
}
.bs3led {
background-color: #10bcd4;
}
.bs4 {
position: absolute;
left:11em;
top: 11em;
background-color: green;
border-bottom-right-radius : 100%;
}
.bs4led{
background-color: #00e600;
}
.red {
background-color: red;
}
#settings {
border: 0.2em solid #fff;
background: #fff;
border-radius: 50%;
position: relative;
z-index: 5;
top: 6em;
left: 5em;
width: 10em;
height: 10em;
}
#roundDisplay {
margin-left: 35%;
margin-top: 5%;
margin-bottom: 5%;
}
.round {
color: #ffcccc;
border: 1px solid red;
max-width: 37px;
text-align: center;
font-size: 1.5em;
}
.roundActive {
color:red;
}
#settingsButtons {
margin-left: 5px;
}
var simon = {
endRounds: 10, //2 for debugging, 20 for real
says: [],
player1: [],
power:true,
stop: false,
strict: false,
reset: function() {
$(".round").html("--");
simon.says = [];
simon.player1 = [];
},
playSound: function(bs) {
var audio = new Audio(simon.sounds[bs]);
audio.play();
},
sounds: {
1: "https://s3.amazonaws.com/freecodecamp/simonSound1.mp3",
2: "https://s3.amazonaws.com/freecodecamp/simonSound2.mp3",
3: "https://s3.amazonaws.com/freecodecamp/simonSound3.mp3",
4: "https://s3.amazonaws.com/freecodecamp/simonSound4.mp3",
5: "https://www.nickmcoyle.com:8080/quote/sound/smb3_no_match.wav",
6: "https://www.nickmcoyle.com:8080/quote/sound/the_price_is_right_theme.wav"
},
startGame: function() {
if(simon.says.length === 0) {
$(".boardSpot").off("click");
simon.makeSequence(simon.animateSequence);
};
},
add: function() {
$(".boardSpot").off("click");
simon.makeSequence(simon.animateSequence);
},
makeSequence: function() {
for(var i = 0; i < 1; i++) {
simon.says.push(simon.getRandom());
};
//update the round display
if(simon.says.length < 1) {
$(".round").html("0" + simon.says.length);
} else {
$(".round").html(simon.says.length);
}
simon.animateSequence();
},
bsClick: function() {
//if power button is turned on then do stuff
if(simon.power) {
var id = $(this).attr("id");
var number = Number(id.substring(2,3));
simon.playSound(number);
//console.log($(this));
simon.player1.push(number);
//add led
$(this).addClass(id+"led");
var that = $(this);
//remove led
var remove = function() {
that.removeClass(id+"led");
};
setTimeout(remove, 400);
simon.testSequence();
};
},
testSequence: function() {
var move = simon.player1.length-1;
var player1Move = simon.player1[move];
var simonMove = simon.says[move];
if(player1Move !== simonMove) {
simon.wrongMoveAnimation();
simon.player1 = [];
if(simon.strict === true) {
simon.reset();
simon.startGame();
return;
};
};
//if end of sequence, then start the next move
if(simon.player1.length === simon.says.length) {
//if reached end of rounds, then player1 wins
if(simon.player1.length === simon.endRounds) {
simon.winGameAnimation();
return;
};
$(".boardSpot").off("click");
simon.player1 = [];
//add the next round after 1.5 seconds delay
setTimeout(function () {simon.add()}, 1500);
};
},
wrongMoveAnimation: function() {
//light all the spots and play the mario sound
simon.playSound(5);
for(var i = 1; i<5; i++) {
var boardSpot = $("#bs"+i);
boardSpot.addClass("bs"+i+"led");
};
//remove led
var remove = function() {
for(var i = 1; i<5; i++) {
var boardSpot = $("#bs"+i);
boardSpot.removeClass("bs"+i+"led");
};
};
setTimeout(remove, 1000);
},
winGameAnimation: function() {
//this function blocks user input, lights all the spots, and plays the win sound
$(".boardSpot").off("click");
simon.playSound(6);
$("#title").html("YOU WIN!!!");
var timer = function() {
simon.stop = true;
};
//start the timer for 33 seconds the same length as the sound clip
setTimeout(timer, 33*1000);
function blink(selector, speed) {
$(selector).fadeOut(speed, function(){
$(this).fadeIn(speed, function(){
if(!simon.stop) {
blink(this);
}
});
});
}
blink('#title', 1000);
setTimeout(blink('#bs1', 0), 100);
setTimeout(blink('#bs2', 250), 400);
setTimeout(blink('#bs3', 500), 800);
setTimeout(blink('#bs4', 1000), 1200);
},
getRandom: function() {
var items = [1,2,3,4];
var random = items[Math.floor(Math.random()*items.length)];
return ( random );
},
animateSequence: function() {
//start with the first boardspot in the simon array
var i = 1;
function animateIt(i) {
var animateFunc = function() {
var id = simon.says[i-1];
simon.playSound(id);
//add led
var boardSpot = $("#bs"+id);
boardSpot.addClass("bs"+id+"led");
//remove led
var remove = function() {
boardSpot.removeClass("bs"+id+"led");
};
setTimeout(remove, 400);
i++;
if(i<=simon.says.length) {
animateIt(i);
} else {
//if the sequence is finished, then allow the player to click
setTimeout(allowClick, 250);
};
};
setTimeout(animateFunc, 1500);
};
animateIt(i);
function allowClick() {
$(".boardSpot").bind("click", simon.bsClick);
};
}
}; //end var simon
$("#startBtn").on("click", function() {
if(simon.power) {
simon.startGame();
};
});
$("#strictToggle").on("click", function() {
if(simon.strict === false) {
$(this).addClass("btn-danger").text("Strict on");
simon.strict = true;
} else {
$(this).removeClass("btn-danger").text("Strict off");
simon.strict = false;
}
});
$("#powerSwitch").on("click", function() {
simon.reset();
if(simon.power === true) {
simon.power = false;
$(".round").removeClass("roundActive");
} else {
simon.power = true;
$(".round").addClass("roundActive");
}
});
$(document).ready( function() {
$("#powerToggle").bootstrapToggle('on');
$(".round").addClass("roundActive");
});
Also see: Tab Triggers