Skip to content

Instantly share code, notes, and snippets.

@biancalpadilla
Created March 29, 2018 15:42
Show Gist options
  • Save biancalpadilla/0cb410b6d30f926ab678fbc5ac078065 to your computer and use it in GitHub Desktop.
Save biancalpadilla/0cb410b6d30f926ab678fbc5ac078065 to your computer and use it in GitHub Desktop.
<script>
let data = {
cutoff: 15,
0: {
day: 'Sunday',
before: { shipsBy: 'Tomorrow', arrivesBy: 'Tuesday or Wednesday'},
after: { shipsBy: 'Tomorrow', arrivesBy: 'Tuesday or Wednesday'}
},
1: {
day: 'Monday',
before: { shipsBy: 'Today', arrivesBy: 'Tuesday or Wednesday'},
after: { shipsBy: 'Tomorrow', arrivesBy: 'Wednesday or Thursday'}
},
2: {
day: 'Tuesday',
before: { shipsBy: 'Today', arrivesBy: 'Wednesday or Thursday'},
after: { shipsBy: 'Tomorrow', arrivesBy: 'Thursday or Friday'}
},
3: {
day: 'Wednesday',
before: { shipsBy: 'Today', arrivesBy: 'Thursday or Friday'},
after: { shipsBy: 'Tomorrow', arrivesBy: 'Friday or Monday'}
},
4: {
day: 'Thursday',
before: { shipsBy: 'Today', arrivesBy: 'Friday or Monday'},
after: { shipsBy: 'Tomorrow', arrivesBy: 'Monday or Tuesday'}
},
5: {
day: 'Friday',
before: { shipsBy: 'Today', arrivesBy: 'Monday or Tuesday'},
after: { shipsBy: 'Monday', arrivesBy: 'Tuesday or Wednesday'}
},
6: {
day: 'Saturday',
before: { shipsBy: 'Monday', arrivesBy: 'Tuesday or Wednesday'},
after: { shipsBy: 'Monday', arrivesBy: 'Tuesday or Wednesday'}
}
};
function estimateMessage(day, time){
if (time < data.cutoff){
return "ships " + data[day].before.shipsBy + ", arrives " + data[day].before.arrivesBy
}
else {
return "ships " + data[day].after.shipsBy + ", arrives " + data[day].after.arrivesBy
}
}
let day = new Date().getDay();
let time = new Date().getHours();
document.getElementById('delivery-date').innerHTML = estimateMessage(day, time);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment