0

JS error

function showTime(){ let date = new.Date(); let hours = Date.getHours(); let minutes = Date.getMinutes(); let seconds = Date.getSeconds(); let formatHours = convertFormat(hours); hours = checkTime(hours); hours = addZero(hours); minutes = addZero(minutes); seconds = addZero(seconds); document.getElementById('clock').innerHTML = `${hours} : ${minutes} : ${seconds} : ${formatHours}`; } function convertFormat(time){ let format = 'AM'; if(time >= 12){ format = 'PM'; } return format; }; function checkTime(time){ if(time > 12){ time = time - 12; } if (time === 0){ time = 12; } return time; }; function addZero(time){ if(time < 10){ time = "0" + time; } return time; }; showTime(); setInterval(showTime,1000); Why is it showing me a SyntaxError,Unexpected Identifier

5th Oct 2020, 5:55 PM
Aldo Margjeka
2 Answers
+ 2
It should be: new Date() let hours = date.getHours(); let minutes = date.getMinutes(); let seconds = date.getSeconds(); not: new.Date() let hours = Date.getHours(); let minutes = Date.getMinutes(); let seconds = Date.getSeconds();
5th Oct 2020, 5:58 PM
Josh Greig
Josh Greig - avatar
+ 3
let date = new Date(); let hours = date.getHours(); let minutes = date.getMinutes(); let seconds = date.getSeconds();
5th Oct 2020, 5:57 PM
Abhay
Abhay - avatar