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

              
                <body>
  
  <div class="bunnytitle">
    <img class="bunnyhead" src="https://raw.githubusercontent.com/AnwenW/bat-the-bunny/master/bunnyhead.png" alt="bunny-logo"><h1>bat<span class="smalltext"> the </span>bunny!</h1><div class="score">0</div>
  </div>

  <div class="intro">
    <div class="startcountdown"><button onClick="startGame()">START</button> » </div>
    <div class="countdownwidth">
      <div id="countdown">10</div> seconds
    </div>
  </div>

  <div class="game">
    <div class="hole hole1">
      <div class="bunny"></div>
    </div>
    <div class="hole hole2">
      <div class="bunny"></div>
    </div>
    <div class="hole hole3">
      <div class="bunny"></div>
    </div>
    <div class="hole hole4">
      <div class="bunny"></div>
    </div>
    <div class="hole hole5">
      <div class="bunny"></div>
    </div>
    <div class="hole hole6">
      <div class="bunny"></div>
    </div>
  </div>

  <footer>
  </footer>

</body>



              
            
!

CSS

              
                html {
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
}

body {
  background: #99d965;
  padding: 0;
  margin: 0;
  font-family: 'Love Ya Like A Sister', sans-serif;
}

.bunnytitle {
  height: 8vw;
  margin-top: 10px;
  text-align: center;
}

.bunnyhead {
  display: inline-block;
  vertical-align: bottom;
  transform: rotate(-5deg);
  width: 5vw;
}

h1 {
  display: inline-block;
  text-align: center;
  font-size: 6vw;
  padding-left: 2vw;
  margin: 0;
}

.smalltext {
  vertical-align: middle;
  font-size: 4vw;
}

.score {
  display: inline-block;
  margin-left: 2vw;
  background: rgba(255,255,255,0.6);
  border-radius: 2vw;
  width: 9.5vw;
  text-align: center;
  font-size: 6vw;
  font-weight: bold;
}

.intro {
  margin: 20px auto 5px;
  width: 80%;
  text-align: center;
}

.startcountdown {
  display: inline-block;
  text-align: center;
  font-size: 1.7em;
}

button {
  display: inline-block;
  background: #ffde26;
  border: 1.5px solid black;
  border-radius: 12px;
  margin-right: 8px;
  padding: 6px 12px 5px;
  font-family: 'Love Ya Like A Sister', sans-serif;
  font-size: 22px;
  letter-spacing: 1.5px;
}

#countdown, .countdownwidth {
  display: inline-block;
  text-align: right;
}

.countdownwidth {
  width: fit-content;
  font-size: 1.7em;
}

#countdown {
  width: 32px;
}

.game {
  width: 600px;
  height: 360px;
  display: flex;
  flex-wrap: wrap;
  margin: 0 auto 20px;
}

.hole {
  flex: 1 0 33.33%;
  overflow: hidden;
  position: relative;
}

.hole:after {
  display: block;
  background: url(https://raw.githubusercontent.com/AnwenW/bat-the-bunny/master/grass1.png) bottom center no-repeat;
  background-size: contain;
  content:'';
  width: 93%;
  height: 70px;
  position: absolute;
  z-index: 2;
  bottom: 0;
}

.bunny {
/*   background-image: url(https://raw.githubusercontent.com/AnwenW/bat-the-bunny/master/bunny1.png); */
  background-position: bottom center;
  background-repeat: no-repeat;
  background-size: 40%;
  position: absolute;
  top: 100%;
  width: 100%;
  height: 100%;
  transition:all 0.4s;
}

.hole.up .bunny {
  top: 0;
}

footer {
  height: 150px;
  background-color: #99d965;
}

@media screen and (max-width: 610px) {
  .bunnytitle {
    height: 11vw;
  }
  .intro {
    margin: 30px auto 5px;
  }
  h1 {
    font-size: 9vw;
    padding-left: 3vw;
  }
  .smalltext {
    font-size: 7vw;
  }
  .bunnyhead {
    width: 8.3vw;
  }
  .score {
    margin-left: 3vw;
    border-radius: 3vw;
    width: 12.5vw;
    font-size: 8vw;
  }
  .game {
    width: 350px;
    height: 400px;
  }
  .hole {
    flex: 1 0 50%;
  }
  .hole:after {
    width: 90%;
  }
  .bunny {
    background-size: 33%;
  }
}

@media screen and (max-width: 420px) {
  .intro {
    margin: 20px auto 5px;
  }
  .game {
    height: 350px;
    width: auto;
  }
  .bunny {
    background-size: 25%;
  }
  .hole {
    flex: 1 0 50%;
  }
  .hole:after {
    width: 73%;
    margin-left: 20px;
  }
}

@media screen and (max-width: 380px) {
  .game {
    height: 330px;
    width: auto;
  }
  .bunny {
    background-size: 26%;
  }
  .hole:after {
    width: 65%;
    margin-left: 22px;
  }
 
}

@media screen and (max-width: 340px) {
  .bunny {
    background-size: 29%;
  }
}
              
            
!

JS

              
                const holes = document.querySelectorAll('.hole');
const scoreBoard = document.querySelector('.score');
const bunnys = document.querySelectorAll('.bunny');
const countdownNum = document.querySelector('#countdown');


let lastHole;
let lastBunny;
let timeUp = false;
let score = 0;
let timeleft = 10;

function randomTime(min, max) {
  return Math.round(Math.random() * (max - min) + min);
}

function randomHole(holes) {
  const idx = Math.floor(Math.random() * holes.length);
  const hole = holes[idx];
  if (hole === lastHole) {
    return randomHole(holes);
  }

  lastHole = hole;
  return hole;
}

function bunnyPicker() {

  const bunny1 = "url('https://raw.githubusercontent.com/AnwenW/bat-the-bunny/master/bunny1.png')";
  const bunny2 = "url('https://raw.githubusercontent.com/AnwenW/bat-the-bunny/master/bunny2.png')";
  const bunny3 = "url('https://raw.githubusercontent.com/AnwenW/bat-the-bunny/master/bunny3.png')";

  const bunnyArray = [bunny1, bunny2, bunny3];

  const bunnyIndex = Math.floor(Math.random() * bunnyArray.length);
  console.log(bunnyIndex);

  for (let i = 0; i < bunnys.length; i++) {
    
    if (bunnyIndex === lastBunny) {
      console.log('Same bunny!');
      return bunnyPicker();
    }
    
    bunnys[i].style.backgroundImage = bunnyArray[bunnyIndex];
  }
  
  lastBunny = bunnyIndex;
  return bunnyIndex;
  
}

function peep() {
  bunnyPicker();
  const time = randomTime(350, 1000);
  const hole = randomHole(holes);
  hole.classList.add('up');
  setTimeout(() => {
    hole.classList.remove('up');
    if (!timeUp) peep();
  }, time);
}

function startGame() {
  scoreBoard.textContent = 0;
  timeleft = 10;
  timeUp = false;
  score = 0;
  peep();
  setTimeout(() => timeUp = true, 10000)
  countdownTimer();
}

function countdownTimer() {
  var timer = setInterval(function() {
      timeleft--;
      countdownNum.textContent = timeleft;
      if (timeleft <= 0)
        clearInterval(timer);
      }, 1000);

      setTimeout(() => {
        countdownNum.textContent = '10';
      }, 11500)
}

function whack(e) {
  if(!e.isTrusted) return; 
  score++;
  this.classList.remove('up');
  scoreBoard.textContent = score;
}

bunnys.forEach(bunny => bunny.addEventListener('click', whack));


              
            
!
999px

Console