looking for some solutions? You are welcome.

SOLVED: my span tag is not updating when appending 0 or changing 0 to 12 in clock

Lightning Resaba:

Span tag is not updating when appending 0 if hour < 10 (e.g 9 = 09) and if hour == 0 (e.g 00 = 12) but it shows in console.log that it changed:

function showTime(){
    const date = new Date();
    const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
    let d = document.getElementById("day").innerHTML = days[date.getDay()];
    let h = document.getElementById("hour").innerHTML = date.getHours();
    let m = document.getElementById("minute").innerHTML = date.getMinutes();
    let s = document.getElementById("second").innerHTML = date.getSeconds();


    if(h == 0){
      h = 12;
    }

    if(h > 12){
      h -= 12
    }

    h = h < 10 ? "0"+h :h;
    m = m < 10 ? "0"+m :m;
    s = s < 10 ? "0"+s :s;


    setTimeout(showTime, 1000);
    console.log(m);
}

showTime();



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent