Low Code Template

For this fiddle to write, debug and test low code for use on ExpertBox.com.

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.4.1/moment-timezone-with-data-2010-2020.min.js"></script>
<body>
  <ul>
    <li id="msg1"></li>
    <li id="msg2"></li>
    <li id="msg3"></li>
    <li id="msg4"></li>
    <li id="msg5"></li>
    <li id="msg6"></li>
    <li id="msg7"></li>
  </ul>
</body>

CSS

body {
  background-color: black;
  color: yellow;
}

JavaScript

// define code under test, with arguments available at runtime
function codeUnderTest(api, data, todayDate, birthDate) {
// START OF CODE UNDER TEST
// ========================

// determine a message based on todays date
// input - birthday - the value from the user interface
// uses - momentjs to make working with dates simpler
// returns - message - a customized birthday message

// do not calculate for future
if (data.options.isFuture) {
  return 'fake';
}

// input validation
if (!todayDate || !birthDate) {
  return 'There is a 1/365 chance it is your birthday today.';
}

// get today and birthdate as moments
var timeZone = data.session.region.timeZone;
var todayMoment = api.moment.tz(todayDate, timeZone);
console.log('today date ', todayDate);
console.log('today moment ', todayMoment.toString());

var birthMoment = api.moment.tz(birthDate, timeZone);
console.log('birth date ', birthDate);
console.log('birth moment ', birthMoment.toString());

// format today and birthdate as strings
var todayString = todayMoment.format('MMDD');
var birthString = birthMoment.format('MMDD');
console.log('today '+todayString+' birth '+birthString)
var isBirthday = todayString === birthString;
console.log('isBirthday ', isBirthday);

// if today is after birth
if (birthMoment.isAfter(todayMoment)) {
  return 'You are not born yet.';
}

// assign message variable with default
var message = 'Today is not your birthday.';

// if it is the user’s birthday today
if (isBirthday) {

  // calculate age
  var age = todayMoment.year() - birthMoment.year();
  console.log('age', age)
   
  // if user if less than 40 years old
  if (age < 40) {
    
    // set message to 'Congratulations on your birthday'
    message = 'Congratulations on your birthday!';
  }
   
  // else
  else {

  //set message to 'Sorry to hear you aged another year'
   message = 'Sorry to hear you aged another year!';
  }
}

// return message
return message;

// ======================
// END OF CODE UNDER TEST
}

//...