JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<body>
<div class="circle-big"></div>
<div id="places">
<button id="place1" value=1 class="up-right color">
<audio id="audio1" src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3"></audio>
</button>
<button id="place2" value=2 class="up-left color">
<audio id="audio2" src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3"></audio>
</button>
<button id="place3" value=3 class="down-left color">
<audio id="audio3" src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3"></audio>
</button>
<button id="place4" value=4 class="down-right color">
<audio id="audio4" src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3"></audio>
</button>
</div>
<div class="circle-small "> </div>
<span id="strict">Strict</span>
<div id="strict-button"></div>
<span id="blind">Blind</span>
<div id="blind-button"></div>
<button id="start" class="toggle">Start</button>
<button id="stop" class="toggle">Stop</button>
<input type="text" class="" id="counter" readonly>
<footer >
<p>Coded by <a href="https://www.freecodecamp.com/tuliodnw" target="_blank">Tulio</a></p>
</footer>
</body>
.color {
position: absolute;
height: 170px;
width: 170px;
margin: auto;
border: none;
}
button:focus {
outline: 0;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
text-align: center;
}
.color:active {
opacity: 0.7;
}
.circle-big {
height: 380px;
width: 380px;
border-radius: 100%;
background-color: #212121;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}
.up-right {
border-radius: 100% 0 0 0;
background-color: #B71C1C;
top: 0;
left: 0;
right: 185px;
bottom: 185px;
}
.up-left{
border-radius: 0 100% 0 0;
background-color: #1c6ab7;
top: 0;
left: 185px;
right: 0;
bottom: 185px;
}
.down-right {
border-radius: 0 0 100% 0;
background-color: #12af23;
top: 185px;
left: 185px;
right: 0;
bottom: 0;
}
.down-left{
border-radius: 0 0 0 100%;
background-color: #FFCA28;
top: 185px;
left: 0;
right: 185px;
bottom: 0;
}
.circle-small {
height: 150px;
width: 150px;
border-radius: 100%;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #EEEEEE;
border: solid 10px #212121;
}
#strict {
top: 0px;
left: 110px;
right: 0;
bottom: 25px;
margin: auto;
position: absolute;
height: 20px;
width: 90px;
}
#blind {
top: 50px;
left: 110px;
right: 0;
bottom: 0px;
margin: auto;
position: absolute;
height: 20px;
width: 90px;
}
#strict-button {
border-radius: 100%;
height: 10px;
width: 10px;
background-color: #212121;
top: 0px;
left: 108px;
right: 0;
bottom: 25px;
margin: auto;
position: absolute;
border: solid 2px #212121;
}
#blind-button {
border-radius: 100%;
height: 10px;
width: 10px;
background-color: #212121;
top: 48px;
left: 108px;
right: 0;
bottom: 0px;
margin: auto;
position: absolute;
border: solid 2px #212121;
}
#counter {
margin-top: 15px;
height: 20px;
width: 55px;
border: none;
background-color: #212121;
color: red;
border-radius: 2px;
text-align: center;
margin: auto;
position: absolute;
top: 45px;
left: 0;
right: 45px;
bottom: 0;
font-size: 0.8em;
}
.hardmode {
background-color: black;
}
.redcalled {
background-color: #e13e3e;
}
.bluecalled {
background-color: #3e90e1;
}
.yellowcalled {
background-color: #ffd75b;
}
.greencalled {
background-color: #25e93a;
}
.toggle {
text-align: center;
background-color: #EEEEEE;
border: solid 2px #212121;
border-radius: 5px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 45px;
bottom: 25px;
height: 25px;
width: 45px;
margin: auto;
}
body {
font-family: "Calibri";
background-color: #EEEEEE;
}
var orden = [], hardmode = false, called = "",strict = false,pause = true, o = 0,inputUsuario = [];
//hide stop button so they dot overlap
$(document).ready(function() {
document.getElementById("counter").value = "--";
$("#stop").hide();
});
//tecla is the strict buton
$("#strict-button").click(function() {
if (strict === false) {
strict = true;
$(this).css({
"background-color": "red"
});
} else {
strict = false;
$(this).css({
"background-color": "#212121"
});
}
});
//tecla2 is the blind mode
$("#blind-button").click(function() {
if (hardmode === false) {
hardmode = true;
$("#blind-button").css({
"background-color": "red"
});
$("#place1,#place2,#place3,#place4").addClass("hardmode");
} else {
$("#place1,#place2,#place3,#place4").removeClass("hardmode");
hardmode = false;
$("#blind-button").css({
"background-color": "#212121"
});
}
});
//start button, hides itself after click
$("#start").click(function() {
o=0;
write();
$("#start").hide();
$("#stop").show();
});
//button that calls the stop function that resets the game
$("#stop").click(function() {
stop();
document.getElementById("counter").value = "--";
$("#stop").hide();
});
//color fills the user array, also checks if the sequence is the same as ai, and check if the user won after doing 20 sequences
$(".color").click(function() {
if (pause === false && orden.length > 0) {
value = parseInt($(this).attr("value"));
inputUsuario.push(value);
var audio = document.getElementById("audio" + value);
audio.play();
if (orden[o] !== inputUsuario[o]) {
if (strict !== true) {
document.getElementById("counter").value = "mistake";
inputUsuario = [];
pause = true;
$('#place1,#place2,#place3,#place4').prop('disabled', true);
startTimer(0);
} else {
document.getElementById("counter").value = "game over";
stop();
}
} else {
if (inputUsuario.length === orden.length) {
if (o != 14) {
inputUsuario = [];
pause = true;
$('#place1,#place2,#place3,#place4').prop('disabled', true);
write(0);
} else {
audio.src = "http://66.90.93.122/ost/pokemon-ten-years-of-pokemon/lcmjyyaprv/1-pokemon-theme-season-theme-.mp3";
audio.play();
$("#place1,#place2").css("background-color", "red");
$("#place3,#place4").css("background-color", "white");
$("#counter").css("width", "80px")
document.getElementById("counter").value = "Catch'Em All";
alert("YOU WON");
stop();
}
}
}
o++;
}
});
//write is the function that push the new color and calls the timer
function write(i) {
if (pause === true) {
o=0;
pos = Math.floor((Math.random() * 4) + 1);
orden.push(pos);
document.getElementById("counter").value = orden.length;
startTimer(0);
}
}
//timer is the one that repeats all the color after a new input or if someone made a mistake
function startTimer(i) {
timer = setInterval(function() {
audio = document.getElementById("audio" + orden[i]);
audio.play();
switch (orden[i]) {
case 1:
called = "redcalled";
break;
case 2:
called = "bluecalled";
break;
case 3:
called = "yellowcalled";
break;
case 4:
called = "greencalled";
}
$("#place" + orden[i]).addClass(called);
setTimeout(function() {
//the 400-orden.length*9, its so the game is faster the longer you are, before i had it too fast
$("#place1,#place2,#place3,#place4").removeClass(called);
}, 400-orden.length*10);
document.getElementById("counter").value = orden.length;
//honestly i have no idea why i must put -2 and no -1, but it just worked
if (i > orden.length - 2) {
pause = false;
$('#place1,#place2,#place3,#place4').prop('disabled', false);
clearInterval(timer);
o = 0;
}
i++;
}, 1000-orden.length*20);
}
//stop is going to be a button that will stop the game so you can start again
function stop() {
$("#place1,#place2,#place3,#place4").removeClass(called);
$('#place1,#place2,#place3,#place4').prop('disabled', false);
clearInterval(timer);
pause = true;
$("#stop").hide();
$("#start").show();
orden = [];
inputUsuario = [];
}
Also see: Tab Triggers