Date manipulation exercise not testing with dates

Date manipulation exercise not testing with dates
0

#1

Tell us what’s happening:

My solution to this exercise wasn’t passing, at all, so I did some debugging and inspection to figure out why. It turns out the exercise isn’t testing my function with a date String. Instead, it appears to be passing in the Chai tests it uses to validate my solution. So, I think there is a bug. Below is what I get when I console.dir the dateString argument the exercise passes to myfunction.

console.dir(dateString)
VM285:1
Object
pass
:
true
testString
:
“assert(typeof add12Hours === ‘function’, ‘add12Hours is a function.’);”
text
:
add12Hours is a function.”
proto
:
Object

Your code so far


function add12Hours (dateString) {
  debugger;
  console.log(typeof dateString);
  var dateStr = dateString.replace(/(AM|PM)/i, ' $1');
  dateStr = dateStr.slice(0, -4);
  var dateObj = new Date(dateStr);
  dateObj.setTime(dateObj.getTime() + (12*60*60*1000));
  var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  var rtnStr = months[dateObj.getMonth()] + " " + dateObj.getDate() + " " + dateObj.getFullYear() + " " + (dateObj.getHours() > 12 ? dateObj.getHours() - 12 : dateObj.getHours()) + ":" + ('0' + dateObj.getMinutes()).slice(-2) + (dateObj.getHours() > 12 ? "pm" : "am") + " EST";

  return rtnStr;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/rosetta-code/date-manipulation/