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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div class="container">
  <div class="row">
    <div class="col-sm-10 mx-auto text-center">
      <div class="card">
          <h2>What City Should You Visit Next</h2>
          <div id="options">
              <hr>
              <h3>Search Options</h3>
              <p>Max Population Size?</p>
              <div class="form-check form-check-inline">
                <input class="form-check-input pop-small" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="Small City">
                <label class="form-check-label" for="inlineRadio1">Small City</label>
              </div>
              <div class="form-check form-check-inline">
                <input class="form-check-input pop-medium" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="Medium City">
                <label class="form-check-label" for="inlineRadio2">Medium City</label>
              </div>
              <div class="form-check form-check-inline">
                <input class="form-check-input pop-large" type="radio" name="inlineRadioOptions" id="inlineRadio3" value="Large City">
                <label class="form-check-label" for="inlineRadio3">Large City</label>
              </div>
              <hr>
            </div>
        <div id="output">??</div>
        <button class="btn btn-primary btn-lg" onclick="displayMatches()"> Roll The Dice</button>
      </div>
    </div>
  </div>
</div>

<div id="createdBy">
  <p>Created By: bNice | 2019</p>
</div>
              
            
!

CSS

              
                body {
  padding-top: 4em;
  background: #159957;  /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #155799, #159957);  /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #155799, #159957); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  font-family: "ZCOOL KuaiLe", cursive;
}

.hidden {
  display: none;
}

#output {
  height: 8rem;
  display: flex;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  font-size: 1.8em;
  padding: 2rem;
  background: lightgreen;
  margin-bottom: 1rem;
  color: #333;
}

.card {
  padding: 4em;
  background: #eee;
  opacity: .8;
}

#createdBy {
  padding: 2em 0 1rem 3rem;
  color: #fff;
}

              
            
!

JS

              
                const smallCities = cities.filter(function(p) {
    return p.population > 36877 && p.population < 150000;
  
  const medCities = cities.filter(function(p) {
    return p.population > 150001 && p.population < 300000;
    
  const largeCities = cities.filter(function(p) {
    return p.population > 300001;


// Convert population values in object from type string type to integer.
function convertJson(cities) {
 for (var i = 0; i<cities.length; i++) {
   cities[i].population = parseInt(cities[i].population, 10);
 }  
}

//add commas to numbers / found on github.
function numberWithCommas(x) {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

//display matches
function displayMatches() {
  const rnum = Math.floor(Math.random() * cities.length);
  //select output id to print to
    const output = document.querySelector("#output");
  //print to id
    output.innerHTML = cities[rnum].city + ', ' + cities[rnum].state + '<br> Population: ' + numberWithCommas(cities[rnum].population);
}

const smallRadio = document.querySelector('.pop-small');
const medRadio = document.querySelector('.pop-med');
const largeRadio = document.querySelector('.pop-large');

console.log(smallRadio.checked);

              
            
!
999px

Console