mercredi 19 septembre 2018

Im trying to get that day - Javascript

I have a script that finds that day, date and year. But to days it should say "I am closed" under the day... those to days is 'Søndag' and 'Onsdag' I have tried to make an if statement but it doesn't seems to work :(

HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>JS - Testing</title>
  </head>
  <body>
    <b id="calendar-day"></b> -
    <b id="calendar-date"></b>
    <b id="calendar-month-year"></b>
    <p></p>
  </body>
  <script src="main.js"></script>
</html>

JS

//function that gets the day and date
function calendar() {
    var day = ['Søndag', 'Mandag','Tirsdag','Onsdag','Torsdag','Fredag','Lørdag'];
    var month = ['Januar','Febuar','Marts','April','Maj','Juni','Juli','August','September','Oktober','November','December'];
    var d = new Date();
    setText('calendar-day', day[d.getDay()]);
    setText('calendar-date', d.getDate());
    setText('calendar-month-year', month[d.getMonth()]+' '+(1900+d.getYear()));
    checkDay();
};

//function that sees if it's closing day
var paragraph = document.querySelector('p');

function checkDay() {
  if (day == 'Onsdag') {
    paragraph.innerText = 'I am closed';
  }
}

function setText(id, val){
    if(val < 10){
        val = '0' + val;    //add leading 0 if val < 10
    }
    document.getElementById(id).innerHTML = val;
};

window.onload = calendar;

Aucun commentaire:

Enregistrer un commentaire