I'm trying to separate concerns using modules in Js eveything is going Ok except that I want to display the time of the system and I did that too but when I output it I got an [object Object]
string and what proves me right that really I got the right system Time is that when I console logged the interCtrl.getTheTime
I got the time of the system and here is a screenshot:
here is my code to let you understand better:
JS:
var controller = (function(interCtrl, UICtrl) {
//1.get the time
setInterval(document.querySelector(".Time").innerHTML = interCtrl.getTime(),100);
// console.log(interCtrl.getTime());
//2.get the date
document.querySelector(".subDate").innerHTML = interCtrl.date();
};
document.querySelector(".add__btn").addEventListener("click", ctrlAddPlans);
document.addEventListener("keypress", function(e) {
if (e.keyCode === 13) {
ctrlAddPlans();
}
});
})(internalController);
var internalController = (function() {
//some code
function getTheDate() {
var newDate;
var d = new Date();
var day = d.getDate();
var year = d.getFullYear();
var month = d.getMonth() + 1;
// var x=1;
if (month.toString().length < 2) {
month = " 0" + month + " ";
}
var date = " %11%/%04%/%2019%";
newDate = date.replace("%11%", day + " ");
newDate = newDate.replace("%04%", month);
newDate = newDate.replace("%2019%", " " + year);
return newDate;
}
function getTheTime() {
//.get the timeDiv
// const timeDiv =
//.get the time (h,m,s)
var date = new Date();
var hours = date.getHours();
if (hours.toString().length < 2) {
hours = `0${hours}`;
}
var mins = date.getMinutes();
if (mins.toString().length < 2) {
mins = `0${mins}`;
}
var seconds = date.getSeconds();
return {
time: hours+ " : "+ mins+" : "+seconds
};
}
return {
date: function getDate() {
return getTheDate();
},
getTime: function getTime() {
return getTheTime();
}
};
})();
I saw this question but it didn't help me what does [object Object] mean?
so any help please and thank you in advance