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;
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
add a comment |
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
you useif (condition) mouseX = when true else when false
as opposed tomouseX = condition ? when true : when false
- note,when false
will be a secondif (condtion) mouseX = when true else mouseX = when false
– Jaromanda X
Mar 26 at 0:39
add a comment |
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
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
javascript
asked Mar 26 at 0:37
Leonardo PetroliLeonardo Petroli
1
1
you useif (condition) mouseX = when true else when false
as opposed tomouseX = condition ? when true : when false
- note,when false
will be a secondif (condtion) mouseX = when true else mouseX = when false
– Jaromanda X
Mar 26 at 0:39
add a comment |
you useif (condition) mouseX = when true else when false
as opposed tomouseX = condition ? when true : when false
- note,when false
will be a secondif (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
add a comment |
3 Answers
3
active
oldest
votes
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.
add a comment |
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;
add a comment |
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 26 at 0:41
Tim BiegeleisenTim Biegeleisen
258k13 gold badges109 silver badges170 bronze badges
258k13 gold badges109 silver badges170 bronze badges
add a comment |
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
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
add a comment |
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Mar 26 at 1:23
thakurinboxthakurinbox
18110 bronze badges
18110 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
you use
if (condition) mouseX = when true else when false
as opposed tomouseX = condition ? when true : when false
- note,when false
will be a secondif (condtion) mouseX = when true else mouseX = when false
– Jaromanda X
Mar 26 at 0:39