From 060ecb3cca86b93bfe682699311d92185dddf8dd Mon Sep 17 00:00:00 2001 From: dj-messi <72274379+dj-messi@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:44:41 -0400 Subject: [PATCH] File(1) added --- script.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 script.js diff --git a/script.js b/script.js new file mode 100644 index 0000000..c70eea5 --- /dev/null +++ b/script.js @@ -0,0 +1,52 @@ +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-=12; + } + if(time === 0) + { + time=12; + } + return time; +} + +function addZero(time) +{ + if(time<10) + { + time='0'+time; + } + return time; + +} +showTime(); +setInterval(showTime,1000); \ No newline at end of file