Nate
Nate

Reputation: 161

convert variable of ternary operator to if-else statement

x = (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0);  
alert(x);

hi guys, how can I convert this variable x to if-else statement returning the variable in true or false result?

thanks a lot

Upvotes: 0

Views: 37

Answers (1)

LF-DevJourney
LF-DevJourney

Reputation: 28564

year = 2010;

if(year % 100 === 0)
    x = (year % 400 === 0);
else
    x = (year % 4 === 0);  
alert(x);

if(year % 100 === 0)
    x = (year % 400 === 0);
else
    x = (year % 4 === 0);  
alert(x);

Upvotes: 1

Related Questions