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

              
                <!-- 
Practicing with the dev interview classic, FizzBuzz! Using Bootstrap 3.

Trying out some techniques described in https://ditam.github.io/posts/fizzbuzz/
My intention is to use some of the more complex methods without overcomplicating the solution.

MVP Requirements:
Just a regular ol' FizzBuzz for now. 1-100, add Fizz if %3 == 0, add Buzz if %5 == 0, else print the number. That's it!
-->
<button class="btn btn-lg btn-block btn-primary" type="submit" onclick="fizzBuzz();">Run FizzBuzz</button></canvas></div><br>
<div class="container-fluid" id="fizzBuzzBox"><div class="col-xs-12">
  
  </div></div>

              
            
!

CSS

              
                html {
  text-align:center;
  font-weight:bold;
  padding:50px;
}

.fizz, .buzz, .fizzbuzz, .i {
  padding:5px;
  margin: 1px;
}

.fizz {
  background-color: #CFF09E;
}
.buzz {
  background-color: #79BD9A;
}
.fizzbuzz {
  background-color: #3B8686;
  background: linear-gradient(-45deg, #CFF09E, #3B8686); 
  color:#fff;
}
.i {
  background-color: #0B486B;
  color:#fff;
}

@media only screen and (max-width:1000px) {

  .fizz, .buzz, .fizzbuzz, .i {
    font-size: .8em;
    padding:2px;
  }
}
@media only screen and (max-width:768px) {
  html {
    padding:0px;
  }
  .fizz, .buzz, .fizzbuzz, .i {
    font-size: .7em;
  }
}
              
            
!

JS

              
                function fizzCheck(n){ 
  return (n%3 === 0);
}
function buzzCheck(n){ 
  return (n%5 === 0);
}

function fizzBuzz(){
	var output = new Array();
  var length;
  
  // Generate array data
  for(var i=1;i<=100;i++){
    if (fizzCheck(i)){
      if (buzzCheck(i)){
        output.push('FizzBuzz');
      } else {
        output.push('Fizz');
      }
    } else if (buzzCheck(i)) {
      output.push('Buzz');
    } else {
      output.push(i);
    }
  }
  
  // Display array data
  output.forEach(function(input){
  var element = document.getElementById('fizzBuzzBox');
  if (input == 'Fizz'){
     element.insertAdjacentHTML("beforeend", '<div class="col-xs-1 fizz">Fizz</div>');
  } else if (input == 'Buzz'){
    /* document.write('<div class="col-med-1 buzz">Buzz</div>'); */ 
     element.insertAdjacentHTML("beforeend", '<div class="col-xs-1 buzz">Buzz</div>');
  }
    else if (input == 'FizzBuzz'){
     element.insertAdjacentHTML("beforeend", '<div class="col-xs-1 fizzbuzz">FizzBuzz!</div>');
  }
    else {
     element.insertAdjacentHTML("beforeend", '<div class="col-xs-1 i">' + input + '</div>');
  }

});
}
              
            
!
999px

Console