Search code examples
javascriptif-statementoperator-keywordternary

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


Solution

  • 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);