reset password
Author Message
jingchao
Posts: 25
Posted 20:55 Nov 19, 2019 |

in the sample code  attendance.html, i didn't understand what this line of code does;

( count > 0 ? count : "" );

 

<script>
$(function(){
    $("td:not(.absences)").click(function(){
        if( $(this).hasClass("green") )
        {
            $(this).removeClass("green").addClass("red");
            var absences = $(this).prevAll().filter(".absences");
            absences.html( Number(absences.text()) + 1 );
        }
        else if( $(this).hasClass("red") )
        {
            $(this).removeClass("red");
            var absences = $(this).prevAll().filter(".absences");
            var count = Number(absences.text()) - 1;
            absences.html( count > 0 ? count : "" );
        }
        else
        {
            $(this).addClass("green");
        }
    })
});
</script>

RosaRock
Posts: 2
Posted 21:06 Nov 19, 2019 |

its a conditional operator

so if the condition (count >0) is true then use count otherwise use ""

https://www.geeksforgeeks.org/ternary-operator-question-mark-and-colon-in-javascript/

jingchao
Posts: 25
Posted 21:11 Nov 19, 2019 |
thanks