Solution 1 :

Assign the href property of the link:

document.getElementById("orders_link").href = isOpen() ? "openURL" : "closedURL";

Of course, replace orders_link, openURL, and closedURL with the appropriate values for your site.

Problem :

I’m working with a delivery business and I’m trying to get the website up and running. The problem I’m having is to get the link in the navigation bar to go to the orders page when we are open and the closed page when we are closed. Here’s what I have so far.

function IsOpen() {
    let inOpenHours;
    let today = new Date().getHours();
    const openHours = {
        openTime: 10,
        closedTime: 21
    if (today >= openHours.openTime && today < openHours.closedTime) {
        inOpenHours = true;
    } else {
        inOpenHours = false;

This part seems to work(at least it did before I made it into a function), the problem is getting it to actually change the link depending on the returned value.


Comment posted by Barmar

Assign the

Comment posted by C. Lewis

What’s with the weirdly-placed

Comment posted by Chris Donaldson

don’t you need them to make the function return if the function is true or false for me to be able to use it to alter the HTML?