JS Help For Basic Plugin *UPDATED* 1 last question, plz help!

I've been working on and off to display a clock in my game and I finally figured out how to get a plugin to display what I want. Simple really, but a big breakthrough for me. Now I need to setup a conditional statement to determine what should be said and when. Right now I'm using...
Spoiler
if $gameVariables.value(99) = 0 {
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth())
this.drawText(":", 12, 0, this.windowWidth())
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth())
this.drawText("AM", 55, 0, this.windowWidth())

};
If I take the conditional part off, it works, but I need the conditional part to toggle AM and PM. Any help would be appreciated.
Single = is an assignment, not a comparison.
Use === instead.
@Andar Thanks for the quick response! Unfortunately the window still doesn't show. I feel like there may be a syntax error with a semicolon or something but I'm not sure.

Edit:
I got it to work when I added the else portion. Kind of. The plugin/script always treats the variable as if it's not 0, even if the debug says it's 0, so the else option is always displayed. Not sure how to fix it, I'll keep working on it.
For the first line, did you try putting the expression you're evaluating in parentheses, like so:
if ($gameVariables.value(99) === 0) {
@SeaPhoenix Yes, I'm currently using...

Spoiler
if ($gameVariables.value[99] === 0){
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("AM", 55, 0, this.windowWidth());
} else {
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("PM", 55, 0, this.windowWidth());
};
};

Actually, I just noticed I was using [] instead of (). I changed it and it now works. Thanks! One more question, how can I get the window to refresh itself? I've searched around forums and pieced together some clues/examples but I can't get the syntax that I found to work with my plugin.

I'm using...
Spoiler
var Clock_HUD_Update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
Clock_HUD_Update.call(this);
this._myWindow.refresh();
};
to attempt to refresh the window.
I'm not an expert, but assuming this._myWindow is defined correctly, does your refresh function for it clear the contents and call the drawing function again (the one in your first spoiler)?

On another note, I'm using Orange HUD so you can also take a look there to see if it does something similar to what you want: https://forums.rpgmakerweb.com/index.php?threads/orange-hud.47186/
Honestly, I'm not sure on either account. I don't really know what I'm doing and the code I wrote to refresh is probably both wrong and in the wrong spot... I suppose it would be easier for me to just post the entire plugin, which is quite small, and ask how I should go about getting it to refresh.

Spoiler
var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
_Scene_Map_start.call(this);
this._myWindow = new Clock_HUD(30, 100);
this.addWindow(this._myWindow);
};

function Clock_HUD() {
this.initialize.apply(this, arguments);
}

Clock_HUD.prototype = Object.create(Window_Base.prototype);
Clock_HUD.prototype.constructor = Clock_HUD;

Clock_HUD.prototype.initialize = function(x, y) {
Window_Base.prototype.initialize.call(this, x, y, this.windowWidth(), this.windowHeight());
if ($gameVariables.value(99) === 0){
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("AM", 55, 0, this.windowWidth());
} else {
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("PM", 55, 0, this.windowWidth());
};
};

Clock_HUD.prototype.windowWidth = function() {
return 450;
};

Clock_HUD.prototype.windowHeight = function() {
return 100

var Clock_HUD_Update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
Clock_HUD_Update.call(this);
this._myWindow.refresh();
};
};
})();
The last bit is meant to refresh it, but taking that out the plugin works as intended. So, how can I get it to refresh?[/spoiler]

Edit:
I've tried that plugin, I've never gotten it to work how I want it. I have my own time system built in the game and it works fine I've just needed a good way to reliably display the time to the player. If I can get this to refresh then the plugin would be more or less perfect after some minor tweaking.
Looks like you're drawing the text only when the window is first initialized, and so just calling it to refresh doesn't draw the text again. There are several ways you can solve this issue; one way would be write a refresh function, move your drawText functions to the refresh function, and then call the refresh function when it's first initialized. Window_Gold in rpg_windows.js does some thing similar, so I suggest taking a look at that.

You may also find Soulpour777's tutorials useful too, especially his "Creating a Basic Window" one: https://soulxregalia.wordpress.com/rmmv-plugin-scripting-tutorials/
Edit:
Everything is working fine but as I was setting things up I ran into one more issue I wanted to get resolved before I start adding all the details to the plugin. This is probably a silly question but, how do I get the window to close? I looked at a few tutorials but I can't seem to figure it out.

Right now I just have it setup so that the window moves off screen but I want the window to toggle on/off depending on if a switch is on/off. However, when I tried to do that and close the window I would either get errors or when the switch is toggled I got horrible lag in game. I didn't want to ask and I wanted to figure it out myself but I'm making little progress and any help would be seriously appreciated. After getting this sorted out I can pretty much get everything else how I want it.

Current code

Spoiler
(function() {

var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
_Scene_Map_start.call(this);
this._myWindow = new Clock_HUD(30, 100);
this.addWindow(this._myWindow);
};
function Clock_HUD() {
this.initialize.apply(this, arguments);
}
Clock_HUD.prototype = Object.create(Window_Base.prototype);
Clock_HUD.prototype.constructor = Clock_HUD;
var _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
this._myWindow.refresh();
};
Clock_HUD.prototype.initialize = function(x, y) {
Window_Base.prototype.initialize.call(this, 1500, 0, this.windowWidth(), this.windowHeight());
this.refresh();
};

Clock_HUD.prototype.windowWidth = function() {
return 350;
};

Clock_HUD.prototype.windowHeight = function() {
return 100
};
Clock_HUD.prototype.refresh = function() {
this.contents.clear();
if ($gameSwitches.value(155) == true){
Clock_HUD.prototype.initialize = function(x, y) {
Window_Base.prototype.initialize.call(this, 1500, -100, this.windowWidth(), this.windowHeight());
this.refresh();
};
} else {
Clock_HUD.prototype.initialize = function(x, y) {
Window_Base.prototype.initialize.call(this, 1500, 0, this.windowWidth(), this.windowHeight());
this.refresh();
};
if ($gameVariables.value(77) === 6){
if ($gameVariables.value(99) === 0){
if ($gameVariables.value(21) < 10){
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":0", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("AM", 55, 0, this.windowWidth());
this.drawText("Sunday", 90, 0, this.windowWidth());
} else {
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("AM", 55, 0, this.windowWidth());
this.drawText("Sunday", 90, 0, this.windowWidth());
};
} else {
if ($gameVariables.value(21) < 10){
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":0", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("PM", 55, 0, this.windowWidth());
this.drawText("Sunday", 90, 0, this.windowWidth());
} else {
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("PM", 55, 0, this.windowWidth());
this.drawText("Sunday", 90, 0, this.windowWidth());
};

};
};
if ($gameVariables.value(77) === 5){
if ($gameVariables.value(99) === 0){
if ($gameVariables.value(21) < 10){
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":0", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("AM", 55, 0, this.windowWidth());
this.drawText("Saturday", 90, 0, this.windowWidth());
} else {
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("AM", 55, 0, this.windowWidth());
this.drawText("Saturday", 90, 0, this.windowWidth());
};
} else {
if ($gameVariables.value(21) < 10){
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":0", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("PM", 55, 0, this.windowWidth());
this.drawText("Saturday", 90, 0, this.windowWidth());
} else {
this.drawText($gameVariables.value(22), 0, 0, this.windowWidth());
this.drawText(":", 12, 0, this.windowWidth());
this.drawText($gameVariables.value(21), 22, 0, this.windowWidth());
this.drawText("PM", 55, 0, this.windowWidth());
this.drawText("Saturday", 90, 0, this.windowWidth());
};
};
};
};
};
})();
Alias/monkey patch Scene_Map.prototype.update. Check the value of the switch and the state of the window. Here's an example.
Spoiler: Code
Code:
/**
 * Create a new clock window.
 * @param {number} [x] - x coordinate. Default: 0
 * @param {number} [y] - y coordinate. Default: 0
 * @returns {Window_Base}
 */
function clockWindow(x, y) {
    "use strict";

    /** @type {Window_Base} */
    var clock = Object.create(Window_Base.prototype);
    var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
    var now = new Date();

    clock.constructor = clockWindow;

    clock.windowWidth = function () {
        return 262;
    };

    clock.windowHeight = function () {
        return clock.lineHeight() * 2;
    };

    clock.refresh = function () {
        var formattedDate =
            days[now.getDay()] + " " + now.toLocaleTimeString();

        clock.contents.clear();
        clock.drawTextEx(formattedDate, 0, 0);
    };

    clock.update = (function (original) {
        return function () {
            original.call(this);
            now = new Date();
            clock.refresh();
        };
    }(clock.update));

    clock.initialize(x, y, clock.windowWidth(), clock.windowHeight());
    clock.refresh();

    return clock;
}

Scene_Map.prototype.update = (function (original) {
    "use strict";

    return function () {
        var switchOn;
        var clock;

        original.call(this);

        switchOn = $gameSwitches.value(1);
        clock = this.clock;

        if (switchOn && clock.isOpen()) {
            return;
        }

        if (switchOn && !clock.isOpen()) {
            return clock.open();
        }

        if (!switchOn && clock.isOpen()) {
            clock.close();
        }
    };
}(Scene_Map.prototype.update));

Scene_Map.prototype.start = (function (original) {
    "use strict";

    return function () {
        original.call(this);

        $gameSwitches.setValue(1, true);

        this.clock = clockWindow();
        this.addWindow(this.clock);
    };
}(Scene_Map.prototype.start));

Original thread: https://forums.rpgmakerweb.com/threads/js-help-for-basic-plugin-updated-1-last-question-plz-help.86050/