Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript error Shop Open and Close Times script

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #30378
    UFNITE
    Member

    I’m using javascript to display open/close times but my script is not working.

    Dreamweaver says their is a syntax error on line 6

    var d = new Date();
    var t_hour = d.getUTCHours(); // getUTC for GMT0
    var t_min = d.getUTCMinutes();
    var t_day = d.getUTCDay();

    if (t_hour == 8 && t_min >= 30 && t_day > 0 && t_day < = 5)
    {
    document.write('open.');
    }
    else if (t_hour > 8 && t_hour < 18 && t_day > 0 && t_day < = 5)
    {
    document.write('open.');
    }
    else
    {
    document.write('closed.');
    }

    and in BODY

    Our shop is.
    #78970
    Bob
    Member

    Try removing the space from line 6, almost all the way at the end of the line.
    Line 6 is now:

    if (t_hour == 8 && t_min >= 30 && t_day > 0 && t_day < = 5)

    whereas it should, I think, be:

    if (t_hour == 8 && t_min >= 30 && t_day > 0 && t_day <= 5)

    Edit: you have the same thing on line 10. Don't know for sure this causes the problem though.

    I removed the space from between the < and the =

    #78978
    UFNITE
    Member

    Thanks Bob, that worked.

    Now to figure out how to sort the days and times

    #78981
    UFNITE
    Member

    Monday: CLOSED
    Tuesday: 9AM – 5:30PM
    Wednesday: 9AM – 5:30PM
    Thursday: 9AM – 5:30PM
    Friday: 12PM – 8PM
    Saturday: 8AM – 2PM
    Sunday: CLOSED

    Say i tried to have

    t_day 3 (tuesday) t_hour == 9 (is that pm or am?)

    how would i specific a closing t_hour to be 5:30PM?

    and if its any later than that how would it display the closed if statement… a greater than sign?

    Thanks.

    #78988
    Bob
    Member

    t_hour == 9 is AM, since getUTCHours() returns the hour from 0-23. So 9 is still AM.

    For 5:30PM, you could do the following:

    var d = new Date();
    var t_hour_minutes = d.getUTCHours() + ":" + d.getUTCMinutes();

    if (t_hour_minutes > "17:30") {
    document.write('closed');
    }

    Edit: I’m not really good with timezones and all that stuff, 5:30PM would seem 17:30 to me, but it might be 18:30 or so because of daylights saving.. I don’t know, but this should get you started.

    #78991
    UFNITE
    Member

    Tuesday open 9:00am close 5:30pm – this doesn’t function properly any idea why?

    if (t_hour == 9 && t_min >= 00 && t_day > 2 && t_day < = 2)
    {
    document.write('open');
    }
    else if (t_hour > 5 && t_hour < 17 && t_min >= 30 && t_day > 2 && t_day <=2)
    {
    document.write('open');
    }
    #78992
    Bob
    Member

    Thats because you made the same error again – you put a space between < and = on line 1. Remove that space.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.