Low Code Template
For this fiddle to write, debug and test low code for use on ExpertBox.com.
by mozfet
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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js"></script>
<body>
<ol id="content"></ol>
</body>
CSS
body {
background-color: black;
color: yellow;
}
.pass {
color: green;
}
.fail {
color: red;
}
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
// input validation
if (!todayDate || !birthDate) {
return 'There is a 1/365 chance it is you birthday today.';
}
// get today and birthdate as moments
var todayMoment = api.moment(todayDate);
console.log('today date ', todayDate);
console.log('today moment ', todayMoment.toString());
var birthMoment = api.moment(birthDate);
console.log('birth date ', birthDate);
console.log('birth moment ', birthMoment.toString());
// format today and birthdate as strings
var todayString = todayMoment.format('MMDD');
var birthString = api.moment(birthDate).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
}
function equals(expected, recieved, testLabel = 'Test') {
const content = $('#content')
if (expected != recieved) {
content.append(`<li...