/    Sign up×
Community /Pin to ProfileBookmark

what dows this mean "(x>=0.5?1:0)"

how should I read this “(x>=0.5?1:0)” in laymen terms? don’t get the expressions. thx

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@french_aceNov 30.2007 — [/QUOTE]
The ? operator is called a ternary operator. Think of it, used with the :, as shorthand for if then else. Read it like if x >= .5, then use 1, else use 0. The expression you have doesn't work by itself. You'd use it like var x = .6; var y =(x >= .5?1:0);alert(y);
Copy linkTweet thisAlerts:
@SyCoNov 30.2007 — Or in laymans terms... ?

If x is greater than or equal to 0.5, then consider the content of the parenthisis to be '1' otherwise consider the content to be 0.
Copy linkTweet thisAlerts:
@Declan1991Dec 01.2007 — It's just like an if statement, and is shorthand for:

if (x>=0.5) {

y = 1;

}

else {

y = 0;

}
×

Success!

Help @crz_06 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...