Practicing Comparisons

Let’s practice working with value types and comparisons (Chapter 4, Pillar 3) where coercion will need to be involved.

scheduleMeeting(..) should take a start time (in 24-hour format as a string “hh:mm”) and a meeting duration (number of minutes). It should return true if the meeting falls entirely within the work day (according to the times specified in dayStart and dayEnd); return false if the meeting violates the work day bounds.

  1. const dayStart = "07:30";
  2. const dayEnd = "17:45";
  3. function scheduleMeeting(startTime,durationMinutes) {
  4. // ..TODO..
  5. }
  6. scheduleMeeting("7:00",15); // false
  7. scheduleMeeting("07:15",30); // false
  8. scheduleMeeting("7:30",30); // true
  9. scheduleMeeting("11:30",60); // true
  10. scheduleMeeting("17:00",45); // true
  11. scheduleMeeting("17:30",30); // false
  12. scheduleMeeting("18:00",15); // false

Try to solve this yourself first. Consider the usage of equality and relational comparison operators, and how coercion impacts this code. Once you have code that works, compare your solution(s) to the code in “Suggested Solutions” at the end of this appendix.