Skip to content
Snippets Groups Projects
Select Git revision
  • main protected
  • test default
2 results

member_group_size_calc.js

Blame
  • member_group_size_calc.js 1.31 KiB
    import $ from "jquery";
    
    $(window).ready(
        () => {
            $("#member-count").on(
                "keypress",
                event => {
                    if (event.key === "Enter") {
                        $("#calculate").click();
                    }
                }
            )
            $("#calculate").on(
                "click",
                event => {
                    const memberCount = Number($("#member-count").val());
    
                    if (isNaN(memberCount) || memberCount === 0) {
                        alert("Prosím, zadej skutečný počet členů.");
                        return;
                    }
    
                    const hundredth = Math.ceil(memberCount / 100);
                    const fifth = Math.ceil(memberCount / 5);
                    const twoSquareRoots = Math.ceil(2 * Math.sqrt(memberCount));
    
                    $("#hundredth").html(hundredth);
                    $("#tenth").html(Math.ceil(memberCount / 10));
                    $("#fifth").html(fifth);
                    $("#two-square-roots").html(twoSquareRoots);
    
                    const motionStart = Math.max(
                        Math.min(fifth, twoSquareRoots), hundredth
                    );
                    const motion = Math.ceil(motionStart / 2);
    
                    $("#member-motion,#ongoing-motion").html(motion);
                    $("#motion-start").html(motionStart);
                }
            );
        }
    )