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" id="commute-calculator">
   <div class="row">
      <div class="col mr-auto ml-auto">
         <label for="basic-url">I work for...</label>
         <div class="input-group mb-3">
           <input type="number" min="1" max="7" v-model="days" class="form-control" id="days" aria-describedby="days">
           <span class="input-group-addon" id="days">days a week</span>
         </div>
         
         <div class="input-group mb-3">
           <input type="number" min="1" max="52" v-model="weeks" class="form-control" id="weeks" aria-describedby="weeks">
           <span class="input-group-addon" id="weeks">weeks in a year</span>
         </div>
         
         <div class="input-group mb-3">
           <span class="input-group-addon" id="minutes">My commute is</span>
           <input type="number" min="1" v-model="travel_time" class="form-control" id="minutes" aria-describedby="minutes">
           <span class="input-group-addon">minutes long</span>
         </div>
      </div>
   </div>
  
   <template v-if="weeks > 0 && days > 0 && travel_time > 0">
      <div class="row custom-card">
         <div class="col-md-10 mr-auto ml-auto">
           <h2 class="text-center">
              Your yearly commute is
           </h2>
            
            <br>

           <ul class="list-group">
              <li class="list-group-item"><strong>{{ total_minutes }}</strong> minutes</li>
              <li class="list-group-item" v-if="total_hours > 0"><strong>{{ total_hours }}</strong> hours</li>
              <li class="list-group-item" v-if="total_days > 0"><strong>{{ total_days }}</strong> days</li>
              <li class="list-group-item" v-if="total_days > 0"><strong>{{ total_weeks }}</strong> weeks</li>

              <li class="list-group-item" v-if="total_sols > 0"><strong>{{ total_sols }}</strong> days on Mars</li>
              <li class="list-group-item" v-if="total_neptunes > 0"><strong>{{ total_neptunes }}</strong> days on Neptune</li>
              <li class="list-group-item" v-if="total_nights > 0"><strong>{{ total_nights }}</strong> good nights' rests</li>
              <li class="list-group-item" v-if="total_podcasts > 0"><strong>{{ total_podcasts }}</strong> podcast episodes</li>
              <li class="list-group-item" v-if="total_audiobooks > 0"><strong>{{ total_audiobooks }}</strong> audiobooks</li>
              <li class="list-group-item" v-if="total_hangovers > 0"><strong>{{ total_hangovers }}</strong> hangovers</li>
              <li class="list-group-item" v-if="total_Windows_loads > 0"><strong>{{ total_Windows_loads }}</strong> Windows desktops booting up</li>
              <li class="list-group-item" v-if="total_Friends_shows > 0"><strong>{{ total_Friends_shows }}</strong> episodes of Friends</li>
              <li class="list-group-item" v-if="total_GoT_finales > 0"><strong>{{ total_GoT_finales }}</strong> Game of Thrones season finales</li>
              <li class="list-group-item" v-if="total_scaramuccis > 0"><strong>{{ total_scaramuccis }}</strong> Scaramuccis</li>
              <li class="list-group-item" v-if="total_kardashians > 0"><strong>{{ total_kardashians }}</strong> Kardashians</li>
           </ul>
        </div>
      </div>
   </template>
   <template v-else>
      <h3 class="mt-4">
         Fill in the above blanks!
      </h3>
   </template>
</div>
              
            
!

CSS

              
                $white: #fbf6ef;
$black: #222023;

body {
   padding: 1rem;
   
   color: $white;
   
   background-color: $black;
}

.custom-card {
   padding: 1.5rem 2rem;
   
   color: $black;
   
   background-color: $white;   
}

              
            
!

JS

              
                var vm = new Vue({
  el: '#commute-calculator',
  data: {
    weeks: null,
    days: null,
    travel_time: null
  },
   computed: {
      minutes: function() {
         let minutes = parseInt(this.travel_time);
         let weeks = parseInt(this.weeks);
         let days = parseInt(this.days);
         let total_time = minutes * 2 * days * weeks;
         
         return total_time;
      },
      hours: function() { return this.minutes / 60; },
      
      total_minutes: function() { return addCommas(this.minutes); },
      total_hours: function() { return addCommas(this.minutes / 60); },
      total_days: function() { return addCommas(this.hours / 24); },
      total_nights: function() { return addCommas(this.hours / 7.5); },
      total_sols: function() { return addCommas(this.minutes / 1480); },
      total_neptunes: function() { return addCommas(this.hours / 16); },
      total_weeks: function() { return addCommas(this.hours / 24 / 7); },
      total_Windows_loads: function() { return addCommas(this.minutes / 25); },
      total_podcasts: function() { return addCommas(this.minutes / 23); },
      total_audiobooks: function() { return addCommas(this.hours / 11); },
      total_hangovers: function() { return addCommas(this.hours / 16); },
      total_Friends_shows: function() { return addCommas(this.minutes / 28); },
      total_GoT_finales: function() { return addCommas(this.minutes / 81); },
      total_scaramuccis: function() { return addCommas(this.hours / 24 / 10); },
      total_kardashians: function() { return addCommas(this.hours / 24 / 72); }
   }
});

function addCommas(nStr) {
	nStr = nStr.toFixed(1);
   nStr += '';
	let x = nStr.split('.');
	let x1 = x[0];
	let x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); }
	
   return (x1 + x2);
}

              
            
!
999px

Console