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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./styles.css">
    
</head>
<body>

<div class="main-container">
    <div class="count-container">
    <div id = 'counter' class='counter'>0</div>
    </div>

    <div class="score-container">
    <div id='circles-clicked' class="circles-clicked">Circles clicked : </div>
    <div id='score' class="score">0</div>
    </div>

    <div class="button-container">
    <button class='start-btn btn' id='start'>Start</button>
    <button class='stop-btn btn' id='stop'>Stop / Reset </button>
</div>

    <div id='circle' class="circle"></div>
    <div id='win' class='win-banner'>You Win!</div>
    <div id='lose' class='lose-banner'>You Lose!</div>
    
</div>






<script src="./script.js"></script>
    
</body>
</html>
              
            
!

CSS

              
                * {
    margin: 0;
    padding: 0;
    
}

.counter{
    font-size: 4rem;
    z-index: 0;
}

.main-container{
    height: 100vh;
    width: 100vw;
    background: rgb(221, 101, 221);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.count-container{
    height: 200px;
    width: 200px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    
}

.score-container{
    height: 50px;
    width: 170px;
    
    position: absolute;
    top: 0;
    left: 0;
}

.circles-clicked{
    margin: .5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    font-size: 1.2rem;
    top: 0;
    left: 0;
}

.score{
    margin: .5rem;
    position: absolute;
    font-size: 1.2rem;
    top: 0;
    right: 0;
    
}

.win-banner{
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 5rem;
    height: 200px;
    width: 400px;
    background: rgba(26, 180, 5, 0.363);
    border-radius: 2rem;
    
    
}

.lose-banner{
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 5rem;
    height: 200px;
    width: 400px;
    background: rgba(255, 0, 0, 0.363);
    border-radius: 2rem;
    
}

.button-container{
    display: flex;
    width: 200px;
    height: 90px;
 
    justify-content: center;
    align-items: center;
    position: absolute;
    bottom: 0;

}

.circle{
    height: 50px;
    width: 50px;
    border-radius: 2rem;
    background: red;
    cursor: pointer;
}

.btn{
    padding: .2rem;
    margin: 1rem;
    border-radius: .5rem;
    border: none;

}

.start-btn{
    width: 50px; 
    cursor: pointer;  
}

.stop-btn{
    width: 90px;
    cursor: pointer;
}




              
            
!

JS

              
                var counter = document.getElementById('counter');
//selects HTML '0'
var count = 0;
//sets count to '0'
var specifiedNumber = 7;
//max number on timer we want to reach
var scoreCount = document.getElementById('score');
var score = 0;
var increasing = true;

//   Start button      Stop/Reset buttons
var startG = document.getElementById('start');
var stopReset = document.getElementById('stop');


//select Win and Lose Banners
var winBanner = document.getElementById('win');
var loseBanner = document.getElementById('lose');



function gameClosure(){
  function game(){
    loseBanner.style.display = 'none';
    winBanner.style.display = 'none';
    counter.style.display = 'block';
    increasing === true ? count++ : count = 0;
    counter.innerHTML = count;
    count === specifiedNumber ? increasing = false : increasing = true;
    if( count === specifiedNumber && score < 5) {
      losingBanner();
    } 
    if (count === specifiedNumber && score >= 5) {
      winningBanner();
    }
  }

  var currentGame;

  return {
    start(){
      loseBanner.style.display = 'none';
      winBanner.style.display = 'none';
      currentGame = setInterval(game, 1000)
      increasing = true;
      count = 0;
      score = 0;
    }, stop() {
      loseBanner.style.display = 'none';
      winBanner.style.display = 'none';
      counter.innerHTML = count;
      count = 0;
      score = 0;
      clearInterval(currentGame)
    }
  }
}

  var game = gameClosure();

  startG.addEventListener('click', game.start);
  stopReset.addEventListener('click', game.stop);

  game.start();
  game.stop();

//when the circle is clicked the circle is moved to a new randomized position on the screen

var circle = document.getElementById('circle');
var spaceWidth;
var spaceHeight;

initCircle();

function initCircle() {
  spaceWidth = screen.height - circle.height;
  spaceHeight = screen.width - circle.width;

  circle.addEventListener('click', moveCircle)
}

function moveCircle(){
  circle.style.top = Math.round(Math.random() * spaceWidth) + 'px';

  circle.style.left = Math.round(Math.random() * spaceHeight) + 'px';
}










  function losingBanner() {
      scoreCount.innerHTML = score;
      counter.style.display = 'none';
      loseBanner.style.display = 'block';
  }

  function winningBanner() {
    scoreCount.innerHTML = score;
    counter.style.display = 'none';
    winBanner.style.display = 'block';
  }

 
  

 

  //to show losing banner
  //======================
  //count has to equal 7
  //score has to be less than 5
  //



  //function loseBanner. Show lose banner if 'count' reaches 'specifiednumber' and 'score' is at 0





















  /*
  myCount = setInterval(function(){
    if(increasing === true) {
      //count++;
    } else {
      count = 0;
    }
  counter.innerHTML = count;
  if(count === specifiedNumber) {
    increasing = false;
  } else if ( count === 0) {
    increasing = true;
  }
  },1000)
  */


//make the count reset everytime it hits ten seconds









// create a counter that automatically counts one for everysecond using settimeout. change inner html of 'count'









              
            
!
999px

Console