mardi 30 janvier 2018

If statement using both && and || operators

I know this has been discussed plenty. I'm pretty sure I'm using proper operator precedence but am still not getting desired results.

In the code below I'm trying to to see if the body has the class "industries" AND if window.location.href is equal to any of the paths separated by || operators. If the class "industries" is present and window.location.href is not equal to any of the paths listed then I want to change the location.

What's happening though is when I enter the path as http://blahblah.com/#leisure It's still executing the code in the if statement and changing the location to https://blahblah.com/#consumer

I have a feeling my explanation is convoluted and shitty. Sorry.

var indDescObj = {
                        aec: "Connecting with <br> customers who build",
                        b2b: "Connecting <br> business to business",
                        consumer: "Connecting <br> with shoppers <br> everywhere they buy",
                        leisure: "Connecting with <br> customers when <br> they're at play"
                }
                var $indDescription = $('.industry-description');
                var $indNavLinks = $('.industry-nav__link');

                $(document).ready(function() {
                        var path = 'http://blahblah.com/'
                        if ( $('body').hasClass('industries') &&
                                                ( (window.location.href !== path + '#consumer') ||
                                                        (window.location.href !== path + '#b2b') ||
                                                        (window.location.href !== path + '#leisure') ||
                                                        (window.location.href !== path +'#aec') )
                                        ) {
                                                $(".industry-nav__link[data-filter='.consumer']").click();
                                                window.location.href = "http://blahblah.com/#consumer";
                        };
                        var hashPath = "." + window.location.hashPath.slice(1);
                        var pathObjKey = path.slice(1);
                        $(".industry-nav__link[data-filter='" + hash + "']").addClass("is-active")
                                $('.industry-description').append(indDescObj[pathObjKey])
                        })

Aucun commentaire:

Enregistrer un commentaire