Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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

Save Automatically?

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 lang="en">
  <head>
      
      <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="style 3.css" />
    <title>Document</title>
    <audio id="clip1">
    <source src="audio/red.mp3"></source>
    </audio>
    <audio id="clip2">
      <source src="audio/green.mp3"></source>
    </audio>
    <audio id="clip3">
      <source src="audio/yellow.mp3"></source>
    </audio>
    <audio id="clip4">
      <source src="audio/blue.mp3"></source>
    </audio>
  </head>
  
  <body >
    <!-- <div class="preload"> -->
      <!-- <img src="" alt="">
      <h3>SIMON</h3>
      <img class = "" src="" alt=""> -->
    <!-- </div> -->
    <nav>
      <button id="start">START</button></nav>
      
      <section id="particles-js">
      <div id="parent">
        <div class="base" id="color1">
          <div class="icon icon1">
            <i class="fas fa-hippo"></i>
          </div>
        </div>
        <div class="base" id="color2">
            <div class="icon icon2">
                <i class="fas fa-cat"></i>
              </div>
        </div>
        <div class="base" id="color3">
            <div class="icon icon3">
                <i class="fas fa-dog"></i>
              </div>
        </div>
        <div class="base" id="color4">
            <div class="icon icon4">
                <i class="fas fa-frog"></i>
              </div>
        </div>
      </div>
      <div id="center" class="score">0</div>
    </section>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.0.min.js"></script>
    <script src="js/particles.js"></script>
    <script src="js/main6.js"></script>
  </body>
</html>

              
            
!

CSS

              
                * {
  padding: 0px;
  margin: 0px;
  box-sizing: border-box;
  font-family: Arial, Helvetica, sans-serif;
}

@keyframes simon {
  0% {
    -webkit-transform: translateY(-60px);
    transform: translateY(-60px);
    -webkit-animation-timing-function: ease-in;
    animation-timing-function: ease-in;
    opacity: 1;
  }

  100% {
    -webkit-transform: translateY(0%);
    transform: translateY(0%);
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
    opacity: 1;
  }
}

@-webkit-keyframes simon {
  0% {
    -webkit-transform: translateY(-60px);
    transform: translateY(-60px);
    -webkit-animation-timing-function: ease-in;
    animation-timing-function: ease-in;
    opacity: 1;
  }

  100% {
    -webkit-transform: translateY(0%);
    transform: translateY(0%);
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
    opacity: 1;
  }
}
body {
  background-color: #26333b;
  display: block;
  height: 100vh;
}

nav {
  display: flex;
  justify-content: center;
  height: 20vh;
  width: 100vw;
  align-items: center;
  position: relative;
  background-color: rgb(175, 83, 187);
  /* border: 2px solid red; */
}

#start {
  background-color: #26333b;
  border: none;
  color: rgba(255, 255, 255, 0.959);
  /* text-decoration: none; */
  height: 50px;
  font-size: 25px;
  width: 45vw;
  cursor: pointer;
  border-radius: 50px;
  position: absolute;
  /* transform: translate(-50% -50%); */

  /* text-decoration: none; */
  transition-property: background-color;
  transition-duration: 500ms;
  z-index: 1;
}

#start:active {
  background-color: rgb(189, 73, 111);

  /* pointer-events: all; 
   background-color: rgb(17, 202, 72);
  border: none; */
  animation: bounce-top 1s;
  -webkit-animation: bounce-top 1s;
  /* transform: translate(-80% -90%); */
  /* color: rgba(255, 255, 255, 0.959); */
  /* text-decoration: none; */
}

/* ######KEYFRAMES */
@-webkit-keyframes bounce-top {
  0% {
    -webkit-transform: translateY(-20%);
    transform: translateY(-20%);
    -webkit-animation-timing-function: ease-in;
    animation-timing-function: ease-in;
    opacity: 1;
  }

  100% {
    -webkit-transform: translateY(0%);
    transform: translateY(0%);
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
    opacity: 1;
  }
}
@keyframes bounce-top {
  0% {
    -webkit-transform: translateY(-20px);
    transform: translateY(-20px);
    -webkit-animation-timing-function: ease-in;
    animation-timing-function: ease-in;
    opacity: 1;
  }

  100% {
    -webkit-transform: translateY(0%);
    transform: translateY(0%);
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
    opacity: 1;
  }
}

#color1 {
  background-color: rgb(48, 214, 192);
  border-radius: 50% 0 0 0;
}

#color2 {
  background-color: rgb(189, 73, 111);
  border-radius: 0 50% 0 0;
}

#color3 {
  background-color: rgb(175, 83, 187);
  border-radius: 0 0% 0% 50%;
}

#color4 {
  background-color: rgb(78, 128, 236);
  border-radius: 0 0% 50% 0%;
}

#parent {
  /* border: 2px solid red; */
  display: grid;
  grid-template-columns: repeat(2, 50%);
  grid-template-rows: repeat(2, 50%);
  top: 27.5%;
  height: 60vh;
  width: 50vw;
  position: absolute;
  /* transform: translateY(-50%); */
  /* border: 1px solid red; */
}

section {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* border: 5px solid blue; */
  height: 100%;
  top: -20vh;
}
#parent div {
  /* border: 5px solid rgb(235, 235, 235); */
  margin: 10px;
  padding: 5px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.active {
  /* background: blue; */
  /* border-color: blue; */
  box-shadow: 0 0px 8px 0 rgb(255, 255, 255), 0 00px 20px 0 rgb(255, 255, 255);
  opacity: 1;
  -webkit-transition: all 0.1s ease;
  -moz-transition: all 0.1s ease;
  -o-transition: all 0.1s ease;
  transition: all 0.1s ease;
}

#center {
  height: 20vh;
  position: absolute;

  width: 20vh;
  background-color: #26333b;
  border-radius: 50%;
  text-align: center;
  color: rgb(237, 247, 248);
  font-size: 7vh;
  line-height: 20vh;
  transform: translateY(35%);
}

.icon {
  /* border: 3px solid #fff; */
  width: 10%;
  height: 10%;
  /* top: 10%; */
  /* left: 15%; */
  font-size: 10vh;
  color: rgb(237, 247, 248);
  /* position: absolute; */
  border-radius: 50%;
  opacity: 0.5;
  -webkit-transition: all 0.1s ease;
  -moz-transition: all 0.1s ease;
  -o-transition: all 0.1s ease;
  transition: all 0.1s ease;
}

/* background-color: rgba(5, 5, 5, 0.5); */

div.icon:hover i {
  color: rgb(241, 246, 247);
  opacity: 0.7;
}
.preload {
  position: fixed;
  top: 0;
  width: 100vw;
  height: 100vh;
  z-index: 5;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgb(175, 83, 187);
  transition: opacity 2s ease;
}

.preload-finish {
  opacity: 0;
  pointer-events: none;
}
.preload h3 {
  /* position: absolute; */
  font-size: 30px;
  color: whitesmoke;
  animation-name: simon;
  animation-duration: 4s;
  animation-iteration-count: 1;
}

              
            
!

JS

              
                // //to import particle library

// particlesJS.load("particles-js", "../assets/particles.json", function() {
//   console.log("callback - particles.js config loaded");
// });

let startButton = document.querySelector("#start");
const turnCounter = document.querySelector("#center");

startButton.addEventListener("click", event => {
  startGame();
});

let order = []; //comp array order
let playerOrder = []; //player moves
let flash; //light
let turn; //whos playing
let correct; //correct answers
let compTurn;
let intervalId; //to be able to clear interval

//to start
function startGame() {
  win = false;
  order = [];
  playerOrder = [];
  flash = 0;
  intervalId = 0;
  turn = 1;
  turnCounter.innerHTML = 1;
  correct = true;
  for (var i = 0; i < 60000; i++) {
    order.push(Math.floor(Math.random() * 4) + 1);
  }
  compTurn = true;
  intervalId = setInterval(gameTurn, 800);
}

function gameTurn() {
  on = false;

  //user turn
  if (flash == turn) {
    clearInterval(intervalId);
    compTurn = false;
    clearColor();
    on = true;
    // console.log(turn);
  }

  if (compTurn) {
    clearColor();
    setTimeout(() => {
      if (order[flash] == 1) one();
      if (order[flash] == 2) two();
      if (order[flash] == 3) three();
      if (order[flash] == 4) four();
      flash++;
    }, 200);
  }
}

let color1 = document.querySelector("#color1");
let color2 = document.querySelector("#color2");
let color3 = document.querySelector("#color3");
let color4 = document.querySelector("#color4");

let icon1 = document.querySelector(".icon1");
let icon2 = document.querySelector(".icon2");
let icon3 = document.querySelector(".icon3");
let icon4 = document.querySelector(".icon4");

let sound = true; //controls sounds triggers

//mix lights and sounds for user
function one() {
  if (sound) {
    let audio = document.getElementById("clip1");
    audio.pause();
    audio.currentTime = 0;
    audio.play();
  }
  sound = true;
  color1.classList.add("active");
  icon1.style.opacity = 1;
}
function two() {
  if (sound) {
    let audio = document.getElementById("clip2");
    audio.pause();
    audio.currentTime = 0;
    audio.play();
  }
  sound = true;
  color2.classList.add("active");
  icon2.style.opacity = 1;
}

function three() {
  if (sound) {
    let audio = document.getElementById("clip3");
    audio.pause();
    audio.currentTime = 0;
    audio.play();
  }
  sound = true;
  color3.classList.add("active");
  icon3.style.opacity = 1;
}
function four() {
  if (sound) {
    let audio = document.getElementById("clip4");
    audio.pause();
    audio.currentTime = 0;
    audio.play();
  }
  sound = true;
  color4.classList.add("active");
  icon4.style.opacity = 1;
}

//clear all styles
function clearColor() {
  color1.classList.remove("active");
  color2.classList.remove("active");
  color3.classList.remove("active");
  color4.classList.remove("active");
  icon1.style.opacity = 0.5;
  icon2.style.opacity = 0.5;
  icon3.style.opacity = 0.5;
  icon4.style.opacity = 0.5;
}

let on = false; //controls click or not click
let win; //wingame

color1.addEventListener("click", event => {
  if (on) {
    playerOrder.push(1);
    compare();
    one();
    if (!win) {
      setTimeout(() => {
        clearColor();
      }, 300);
    }
  }
});

color2.addEventListener("click", event => {
  if (on) {
    playerOrder.push(2);
    compare();
    two();
    if (!win) {
      setTimeout(() => {
        clearColor();
      }, 300);
    }
  }
});

color3.addEventListener("click", event => {
  if (on) {
    playerOrder.push(3);
    compare();
    three();
    if (!win) {
      setTimeout(() => {
        clearColor();
      }, 300);
    }
  }
});

color4.addEventListener("click", event => {
  if (on) {
    playerOrder.push(4);
    compare();
    four();
    if (!win) {
      setTimeout(() => {
        clearColor();
      }, 300);
    }
  }
});

function compare() {
  if (playerOrder[playerOrder.length - 1] !== order[playerOrder.length - 1])
    correct = false;

  console.log(playerOrder.length);
  console.log(playerOrder);

  //if winns
  if (playerOrder.length == 20 && correct) {
    winGame();
    console.log(playerOrder.length);
  }

  //if misstake
  if (correct == false) {
    flashColor();
    turnCounter.innerHTML = "WRONG!";
    startButton.innerHTML = "RETRY";
    setTimeout(() => {
      turnCounter.innerHTML = turn;
      clearColor();
      compTurn = true;
      flash = 0;
      playerOrder = [];
      correct = true;
      startGame();
    }, 800);
    sound = false;
  }

  //if correct
  if (turn == playerOrder.length && correct && !win) {
    turn++;
    playerOrder = [];
    compTurn = true;
    flash = 0;
    turnCounter.innerHTML = turn;

    intervalId = setInterval(gameTurn, 800);
    //console.log(turn);
  }
}
//flash color for mistake and win
function flashColor() {
  color1.classList.add("active");
  color2.classList.add("active");
  color3.classList.add("active");
  color4.classList.add("active");
  icon1.style.opacity = 1;
  icon2.style.opacity = 1;
  icon3.style.opacity = 1;
  icon4.style.opacity = 1;
}
//win!!!
function winGame() {
  flashColor();
  turnCounter.innerHTML = "WIN!";
  startButton.innerHTML = "RETRY";
  on = false;
  win = true;
}


              
            
!
999px

Console