vendredi 5 février 2016

If..else statement not working as expected

I have a network design app which performs a simulation of a packet traversing the network given particular conditions which looks like this: enter image description here When I click on the Config button, I have an if..else statement which verifies whether the network prefix(the number after the slash /48 /64 etc) are the same, and if they are the same, the packet travels along the line.

As you can see the first two prefixes are the same and therefore the packet has traveled along the line(showcased by the green line) and for the last computer, the prefix is 64 and it hasn't been able to reach there.

This if statement is supposed to check for that:

CODES

/* enter is the ip entered */
if (enter != null) {

    /*Verify if all prefixes are the same*/

/* s is the array that contains the prefixes */
    if (s[0] == s[1]) {

/*every code in the if statement is for the animations*/

        var start = $("#sldr");
        if (!start.hasClass('started')) {
            start.addClass('started');

            $('#sldr').css({
                "left": startx[0],
                "top": 160 + starty[0],
                "visibility": "visible"
            });


            $("#sldr").css({
                'display': 'block',
                'transition': 'none',
                'width': '50px'

            }).animate({
                        left: endx[0] - 15,
                        top: 160 + endy[0]

                    }, 2000,
                    function () {
                        //add if statements here
                        //for lines: give a specific color of line and specify which kind of cables it is
                        //retrieve the values and add conditions, same for the devices
                        //save the line coordinates in an array and use it for the animation
                        paths[0].attr("stroke", "green");
                        start.removeClass('started');
                        $('#sldr').css('visibility', 'hidden'); //remove this for ease in width
                        $('#img2').css('visibility', 'visible');
                    });

        }
    }
    else if (s[1] == s[2]) {

        var start2 = $("#img2");
        if (!start2.hasClass('started')) {
            start2.addClass('started');

            $('#img2').css({
                "left": startx[1],
                "top": 160 + starty[1]
            });


            $("#img2").delay(2000).css({
                'display': 'block',
                'transition': 'none',
                'width': '50px'

            }).animate({
                        left: endx[1] - 15,
                        top: 160 + endy[1]

                    }, 2000,
                    function () {
                        //add if statements here
                        //for lines: give a specific color of line and specify which kind of cables it is
                        //retrieve the values and add conditions, same for the devices
                        //save the line coordinates in an array and use it for the animation
                        paths[1].attr("stroke", "green");
                        start2.removeClass('started');
                        $('#img2').css('visibility', 'hidden'); //remove this for ease in width

                    });
        }
    }
    else {
        $('#errorPrefix').dialog({ //dialog box for error message that prefix is not the same
            height: 190,
            width: 330,
            modal: true,
            buttons: {
                Ok: function () {
                    $(this).dialog("close");
                }
            },
            resizable: false,
            dialogClass: 'no-close error-dialog'
        });
    }

}

else {
           $('#error').dialog({ //dialog for the error message that ip hasn't been set
           height: 190,
           width: 330,
           modal: true,
           buttons: {
           Ok: function () {
               $(this).dialog("close");
            }
           },
           resizable: false,
           dialogClass: 'no-close error-dialog'
                    });
           }

The problem here is that the dialog box which displays the error message that the prefix is not same is not opening.

Any problem in my if..else statement?

Aucun commentaire:

Enregistrer un commentaire