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>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Ovulation Predictor Calc in Vue</title>
</head>
<body>

  <section class="hero is-primary has-text-centered">
  <div class="hero-body">
    <div class="container">
      <h1 class="title is-1">Ovulation Predictor Calculator</h1>
    </div>
  </div>
  </section>
  
  <section id="app" class="section content has-text-centered">
    
<transition name="fade" mode="out-in">
    <div class="content columns level is-centered
" v-if="!calcReturned" key="calendar">

      <div class="column is-one-third level has-text-centered ">
        <p class="subtitle">Please select the first day of your last menstrual period:</p>
        <vuejs-datepicker :inline="true" v-model="date">{{ date }}</vuejs-datepicker>
      </div>

      <div class="column is-one-third has-text-centered level">
        <p>Usual number of days in your cycle:</p>
        <div class="select is-primary">
          <select name="days" v-model="cycleSelected">
            <option v-for="n in 45" v-if="n >= 20">{{ n }}</option>
          </select>
        </div>

        <div class="level-item">
          <button class="button is-large is-primary is-rounded " id="calculate-btn" @click="startCalc(); calculateFertileBegin(); calculateFertileEnds(); calculateDueDate();">Calculate</button>
        </div>
      </div>
    </div>

    <div class="content has-text-centered" v-else key="result">

      <p class="subtitle">Here are the results based on the information you provided:</p>
      <p>Your next most fertile period is <strong>{{ fertileFrom }}</strong> to <strong>{{ fertileUntil }}</strong>.</p>
      <p>If you conceive within this timeframe, your estimated due date will be <strong>{{ dueDate }}</strong>.</p>
      <div class="level-item">
        <button class="button is-large is-primary is-rounded" id="resetCalc" @click="resetCalc">Calculate Again</button>
      </div>

    </div>
</transition>
    
    <div class="notification is-full">*Average length will vary by woman. **A woman's best days to conceive can start at least one day prior and last at least one day after fertile date.
    </div>

  </section>
</body>

</html>
              
            
!

CSS

              
                /* Override Vue Datepicker CSS */

.vdp-datepicker__calendar {
    width: 100% !important;
}
.vdp-datepicker__calendar .cell.selected {
    background: #00d2b2 !important;
    color: #fff;
    font-weight: bold;
}
.vdp-datepicker__calendar .cell:not(.blank):not(.disabled).day:hover, .vdp-datepicker__calendar .cell:not(.blank):not(.disabled).month:hover, .vdp-datepicker__calendar .cell:not(.blank):not(.disabled).year:hover {
    border: 1px solid #00d2b2 !important;
}
.vdp-datepicker__calendar .cell.selected:hover {
    background: #00d2b2 !important;
}
.select {
  margin-bottom: 1em;
}
.fade-enter {
  opacity: 0;
}
.fade-enter-active {
  transition: opacity 1.5s;
}
.fade-leave {
  opacity: 0;
}
.fade-leave-active {
}
              
            
!

JS

              
                // Ovulation Predictor Calculator using Vue.js + Vue Datepicker + MomentJS + Bulma CSS

new Vue({
  el: '#app',
  components: {
  	vuejsDatepicker
  },
  data() {
    return {
      calcReturned: false,
      date: new Date(),
      cycleSelected: 28,
      fertileFrom: "",
      fertileUntil: "",
      dueDate: "",
      fullDate: "",
    };
  },
  methods: {
    startCalc: function() {
      this.calcReturned = true;
    },
    calcDate: function() {
      var day = parseInt(document.querySelector("span.day.selected").innerHTML);
      var month = document.querySelector("span.month.selected").innerHTML;
      var year = parseInt(document.querySelector("span.year.selected").innerHTML);

      var months = [
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
      ];
      
      months.forEach(function (value, i) {
      if (value === month && i <= 8 ) {
        i ++;
        month = "0" + i.toString();
      } else if (value === month && i >= 9 ) {
          i ++;
        month = i.toString();
      }
      });
      
      this.fullDate = year + "" + month + "" + day;
    },
    calculateFertileBegin: function() {
      this.calcDate();
      if ( this.cycleSelected === 28) {
        this.fertileFrom = moment(this.fullDate, 'YYYYMMDD').add(12, 'days').format('MMMM Do YYYY');
      } else {
          this.fertileFrom = moment(this.fullDate, 'YYYYMMDD').add(this.cycleSelected - 28 + 12, 'days').format('MMMM Do YYYY');  
      }
    },    
    calculateFertileEnds: function() {
      //this.calcDate(); is called from calculateFertileBegin
      if ( this.cycleSelected === 28) {
        this.fertileUntil = moment(this.fullDate, 'YYYYMMDD').add(16, 'days').format('MMMM Do YYYY');
      } else {
          this.fertileUntil = moment(this.fullDate, 'YYYYMMDD').add(this.cycleSelected - 28 + 16, 'days').format('MMMM Do YYYY');  
      }
    },
    calculateDueDate: function() {
      //this.calcDate(); is called from calculateFertileBegin
      if ( this.cycleSelected === 28) {
        this.dueDate = moment(this.fullDate, 'YYYYMMDD').add(280, 'days').format('MMMM Do YYYY');
      } else {
          this.dueDate = moment(this.fullDate, 'YYYYMMDD').add(this.cycleSelected - 28 + 280, 'days').format('MMMM Do YYYY');  
      }
    },
    resetCalc: function() {
      this.calcReturned = false;
      this.date = new Date();
      this.cycleSelected = 28;
      this.fertileFrom = "";
      this.fertileUntil = "";
      this.dueDate = "";
      this.fullDate = "";
    },
  },
});


              
            
!
999px

Console