Code defined to function at a certain time

1

I have a code that should work at a certain time, but it is not working.

$(function() {
    $(".post").each(function() {
        var d = new Date();
        var hora = d.getHours();
        if (hora <= 7 && hora >= 22) {
            alert("O código está funcionando!");
            if (_userdata.user_level == 2 || _userdata.user_level == 1) {
                return;
            }
            if ($('.pathname-box:contains(Tarefas), .pathname-box:contains(Redações)').length > 0) {
                var username = _userdata.username;
                if ($(this).has('.staff').length) {
                    return;
                }
                if ($(this).html().indexOf(username) <= 1) {
                    $(this).remove();
                }
                if ($(this).html().indexOf(username) >= 1) {
                    $(this).remove();
                }
            }
        }
    });
});

Part of setting the time:

            var d = new Date();
            var hora = d.getHours();
            if (hora <= 7 && hora >= 22) {

Note: If I remove the part where it sets the time the code should work, it starts working so it can not be code problem.

Unlicensed code:

$(function() {
    $(".post").each(function() {
            alert("O código está funcionando!");
            if (_userdata.user_level == 2 || _userdata.user_level == 1) {
                return;
            }
            if ($('.pathname-box:contains(Tarefas), .pathname-box:contains(Redações)').length > 0) {
                var username = _userdata.username;
                if ($(this).has('.staff').length) {
                    return;
                }
                if ($(this).html().indexOf(username) <= 1) {
                    $(this).remove();
                }
                if ($(this).html().indexOf(username) >= 1) {
                    $(this).remove();
                }
            }
        }
    });
});
    
asked by anonymous 16.10.2015 / 19:55

1 answer

3

This if (hora <= 7 && hora >= 22) { condition is impossible. Is there no number that is both less than or equal to seven and greater than or equal to 22?

I think you want to use the or operator, that is: ||

if (hora <= 7 || hora >= 22) {

And so run the code between zero hours and 7 (inclusive) and later after 10 pm until the end of the day.

    
16.10.2015 / 20:14