How to translate this ternary operator expression into if/else blocks?How to force the browser to reload cached CSS/JS files?How do you access the matched groups in a JavaScript regular expression?How do you use a variable in a regular expression?Ternary operation in CoffeeScriptIs Safari on iOS 6 caching $.ajax results?JS ternary operator vs if/elseTurning a ternary operator into if else statement on returnConvert ternary operator statement to normal if/elseif/else statementif else-works,if else with ternary operator doesn't workOnly ternary operator works here

How to drill holes in 3/8" steel plates?

Is that a case of "DOUBLE-NEGATIVES" as claimed by Grammarly?

What the real concept of Static keyword in perspective of Embedded C. See below code

When I press the space bar it deletes the letters in front of it

How can I effectively communicate to recruiters that a phone call is not possible?

Is it OK to leave real names & info visible in business card portfolio?

Reverse dots and boxes

How do native German speakers usually express skepticism (using even) about a premise?

Misrepresented my work history

Integer Lists of Noah

Backspace functionality in normal mode

What is the correct parsing of お高くとまる?

Party going through airport security at separate times?

Postgres trigram match acting strange for specific characters

How can a dictatorship government be beneficial to a dictator in a post-scarcity society?

Data Encryption by Application vs Data Encryption in Database

Yet another hash table in C

What are the original Russian words for a prostitute?

Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?

How quality assurance engineers test calculations?

[Future]Historical experience as a guide to warship design?

What's the point of having a RAID 1 configuration over incremental backups to a secondary drive?

Elf (adjective) vs. Elvish vs. Elven

Graduate student with abysmal English writing skills, how to help



How to translate this ternary operator expression into if/else blocks?


How to force the browser to reload cached CSS/JS files?How do you access the matched groups in a JavaScript regular expression?How do you use a variable in a regular expression?Ternary operation in CoffeeScriptIs Safari on iOS 6 caching $.ajax results?JS ternary operator vs if/elseTurning a ternary operator into if else statement on returnConvert ternary operator statement to normal if/elseif/else statementif else-works,if else with ternary operator doesn't workOnly ternary operator works here






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am having a hard time to "translate" this expression using JS ternary operators into if/else statement, which help me visualise better what is happening in the code.




mouseX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);









share|improve this question






















  • you use if (condition) mouseX = when true else when false as opposed to mouseX = condition ? when true : when false - note, when false will be a second if (condtion) mouseX = when true else mouseX = when false

    – Jaromanda X
    Mar 26 at 0:39


















0















I am having a hard time to "translate" this expression using JS ternary operators into if/else statement, which help me visualise better what is happening in the code.




mouseX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);









share|improve this question






















  • you use if (condition) mouseX = when true else when false as opposed to mouseX = condition ? when true : when false - note, when false will be a second if (condtion) mouseX = when true else mouseX = when false

    – Jaromanda X
    Mar 26 at 0:39














0












0








0








I am having a hard time to "translate" this expression using JS ternary operators into if/else statement, which help me visualise better what is happening in the code.




mouseX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);









share|improve this question














I am having a hard time to "translate" this expression using JS ternary operators into if/else statement, which help me visualise better what is happening in the code.




mouseX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);






javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 0:37









Leonardo PetroliLeonardo Petroli

1




1












  • you use if (condition) mouseX = when true else when false as opposed to mouseX = condition ? when true : when false - note, when false will be a second if (condtion) mouseX = when true else mouseX = when false

    – Jaromanda X
    Mar 26 at 0:39


















  • you use if (condition) mouseX = when true else when false as opposed to mouseX = condition ? when true : when false - note, when false will be a second if (condtion) mouseX = when true else mouseX = when false

    – Jaromanda X
    Mar 26 at 0:39

















you use if (condition) mouseX = when true else when false as opposed to mouseX = condition ? when true : when false - note, when false will be a second if (condtion) mouseX = when true else mouseX = when false

– Jaromanda X
Mar 26 at 0:39






you use if (condition) mouseX = when true else when false as opposed to mouseX = condition ? when true : when false - note, when false will be a second if (condtion) mouseX = when true else mouseX = when false

– Jaromanda X
Mar 26 at 0:39













3 Answers
3






active

oldest

votes


















2














We can try writing:



if (window.Event) 
mouseX = e.pageX;

else
var scroll;
if (document.documentElement.scrollLeft)
scroll = document.documentElement.scrollLeft;

else
scroll = document.body.scrollLeft;

mouseX = event.clientX + scroll;



I pulled out the nested ternary expression into a variable scroll. This makes it much easier to rewrite the logic.






share|improve this answer






























    2














    It'll be clearer if you indent your original code - changing only whitespace, your original code is:



    mouseX = (window.Event)
    ? e.pageX
    : event.clientX + (
    document.documentElement.scrollLeft
    ? document.documentElement.scrollLeft
    : document.body.scrollLeft
    );


    Translating that, you get:



    if (window.Event)
    mouseX = e.pageX;
    else
    let add;
    if (document.documentElement.scrollLeft)
    add = document.documentElement.scrollLeft;
    else
    add = document.body.scrollLeft;
    mouseX = event.clientX + add;






    share|improve this answer
































      0














      First of all I want to suggest you to use some linting (eslint, jslint, tslint etc) tool and prettier. To have better code formatting. It helps in long run.



      The other answers are also valid. But I want to write one.



      if (window.Event) 
      mouseX = e.pageX;
      else
      let scroll;
      if (document.documentElement.scrollLeft)
      scroll = document.documentElement.scrollLeft;
      else
      scroll = document.body.scrollLeft;

      mouseX = event.clientX + scroll;






      share|improve this answer

























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348289%2fhow-to-translate-this-ternary-operator-expression-into-if-else-blocks%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        We can try writing:



        if (window.Event) 
        mouseX = e.pageX;

        else
        var scroll;
        if (document.documentElement.scrollLeft)
        scroll = document.documentElement.scrollLeft;

        else
        scroll = document.body.scrollLeft;

        mouseX = event.clientX + scroll;



        I pulled out the nested ternary expression into a variable scroll. This makes it much easier to rewrite the logic.






        share|improve this answer



























          2














          We can try writing:



          if (window.Event) 
          mouseX = e.pageX;

          else
          var scroll;
          if (document.documentElement.scrollLeft)
          scroll = document.documentElement.scrollLeft;

          else
          scroll = document.body.scrollLeft;

          mouseX = event.clientX + scroll;



          I pulled out the nested ternary expression into a variable scroll. This makes it much easier to rewrite the logic.






          share|improve this answer

























            2












            2








            2







            We can try writing:



            if (window.Event) 
            mouseX = e.pageX;

            else
            var scroll;
            if (document.documentElement.scrollLeft)
            scroll = document.documentElement.scrollLeft;

            else
            scroll = document.body.scrollLeft;

            mouseX = event.clientX + scroll;



            I pulled out the nested ternary expression into a variable scroll. This makes it much easier to rewrite the logic.






            share|improve this answer













            We can try writing:



            if (window.Event) 
            mouseX = e.pageX;

            else
            var scroll;
            if (document.documentElement.scrollLeft)
            scroll = document.documentElement.scrollLeft;

            else
            scroll = document.body.scrollLeft;

            mouseX = event.clientX + scroll;



            I pulled out the nested ternary expression into a variable scroll. This makes it much easier to rewrite the logic.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 0:41









            Tim BiegeleisenTim Biegeleisen

            258k13 gold badges109 silver badges170 bronze badges




            258k13 gold badges109 silver badges170 bronze badges























                2














                It'll be clearer if you indent your original code - changing only whitespace, your original code is:



                mouseX = (window.Event)
                ? e.pageX
                : event.clientX + (
                document.documentElement.scrollLeft
                ? document.documentElement.scrollLeft
                : document.body.scrollLeft
                );


                Translating that, you get:



                if (window.Event)
                mouseX = e.pageX;
                else
                let add;
                if (document.documentElement.scrollLeft)
                add = document.documentElement.scrollLeft;
                else
                add = document.body.scrollLeft;
                mouseX = event.clientX + add;






                share|improve this answer





























                  2














                  It'll be clearer if you indent your original code - changing only whitespace, your original code is:



                  mouseX = (window.Event)
                  ? e.pageX
                  : event.clientX + (
                  document.documentElement.scrollLeft
                  ? document.documentElement.scrollLeft
                  : document.body.scrollLeft
                  );


                  Translating that, you get:



                  if (window.Event)
                  mouseX = e.pageX;
                  else
                  let add;
                  if (document.documentElement.scrollLeft)
                  add = document.documentElement.scrollLeft;
                  else
                  add = document.body.scrollLeft;
                  mouseX = event.clientX + add;






                  share|improve this answer



























                    2












                    2








                    2







                    It'll be clearer if you indent your original code - changing only whitespace, your original code is:



                    mouseX = (window.Event)
                    ? e.pageX
                    : event.clientX + (
                    document.documentElement.scrollLeft
                    ? document.documentElement.scrollLeft
                    : document.body.scrollLeft
                    );


                    Translating that, you get:



                    if (window.Event)
                    mouseX = e.pageX;
                    else
                    let add;
                    if (document.documentElement.scrollLeft)
                    add = document.documentElement.scrollLeft;
                    else
                    add = document.body.scrollLeft;
                    mouseX = event.clientX + add;






                    share|improve this answer















                    It'll be clearer if you indent your original code - changing only whitespace, your original code is:



                    mouseX = (window.Event)
                    ? e.pageX
                    : event.clientX + (
                    document.documentElement.scrollLeft
                    ? document.documentElement.scrollLeft
                    : document.body.scrollLeft
                    );


                    Translating that, you get:



                    if (window.Event)
                    mouseX = e.pageX;
                    else
                    let add;
                    if (document.documentElement.scrollLeft)
                    add = document.documentElement.scrollLeft;
                    else
                    add = document.body.scrollLeft;
                    mouseX = event.clientX + add;







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 26 at 0:43

























                    answered Mar 26 at 0:40









                    CertainPerformanceCertainPerformance

                    117k16 gold badges78 silver badges107 bronze badges




                    117k16 gold badges78 silver badges107 bronze badges





















                        0














                        First of all I want to suggest you to use some linting (eslint, jslint, tslint etc) tool and prettier. To have better code formatting. It helps in long run.



                        The other answers are also valid. But I want to write one.



                        if (window.Event) 
                        mouseX = e.pageX;
                        else
                        let scroll;
                        if (document.documentElement.scrollLeft)
                        scroll = document.documentElement.scrollLeft;
                        else
                        scroll = document.body.scrollLeft;

                        mouseX = event.clientX + scroll;






                        share|improve this answer



























                          0














                          First of all I want to suggest you to use some linting (eslint, jslint, tslint etc) tool and prettier. To have better code formatting. It helps in long run.



                          The other answers are also valid. But I want to write one.



                          if (window.Event) 
                          mouseX = e.pageX;
                          else
                          let scroll;
                          if (document.documentElement.scrollLeft)
                          scroll = document.documentElement.scrollLeft;
                          else
                          scroll = document.body.scrollLeft;

                          mouseX = event.clientX + scroll;






                          share|improve this answer

























                            0












                            0








                            0







                            First of all I want to suggest you to use some linting (eslint, jslint, tslint etc) tool and prettier. To have better code formatting. It helps in long run.



                            The other answers are also valid. But I want to write one.



                            if (window.Event) 
                            mouseX = e.pageX;
                            else
                            let scroll;
                            if (document.documentElement.scrollLeft)
                            scroll = document.documentElement.scrollLeft;
                            else
                            scroll = document.body.scrollLeft;

                            mouseX = event.clientX + scroll;






                            share|improve this answer













                            First of all I want to suggest you to use some linting (eslint, jslint, tslint etc) tool and prettier. To have better code formatting. It helps in long run.



                            The other answers are also valid. But I want to write one.



                            if (window.Event) 
                            mouseX = e.pageX;
                            else
                            let scroll;
                            if (document.documentElement.scrollLeft)
                            scroll = document.documentElement.scrollLeft;
                            else
                            scroll = document.body.scrollLeft;

                            mouseX = event.clientX + scroll;







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 26 at 1:23









                            thakurinboxthakurinbox

                            18110 bronze badges




                            18110 bronze badges



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348289%2fhow-to-translate-this-ternary-operator-expression-into-if-else-blocks%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현