<!-- It is possible to find which element was selected. -->
<!-- Using $(this) in an event function does just that. -->
<!-- var elm = $(this) sets elm to the clicked element. -->

<script>
    li = $("li");
    function toggleStriked() {
        $(this).toggleClass("striked");
    }
    li.on("click", toggleStriked);
    
    h2 = $("h2"); // This sets h2 to all h2 elements.
    function toggleBold() {
        // $() also accepts 'this' as an argument.
        // 'this', when inside of an event function is...
        // ... the specific target for the event!
        // Look at "toggleStriked" for an example.
        // Toggle the class "bold" on the clicked h2:
            $(h2).toggleClass("bold");
    }
    // When any h2 is clicked, perform "toggleBold".
    h2.on("click", toggleBold);
</script>
<style>
    .bold {
        font-weight:bold;
        font-size:xx-large;
    }
    .striked {
        text-decoration:line-through;
    }

<!-- To select neighboring elements, use "siblings()" -->
<!-- Use this to unfocus elements next to a target. -->
<!-- Elements are neighbors when at similar identation. -->

<script>
    var selectable = $(".selectable");
    function focusSelected() {
        var targetElement = $(this);
        var siblings = targetElement.siblings();
        siblings.addClass("mute");
        // Use removeClass() to remove "sel" from siblings.
        siblings.removeClass("sel");
        targetElement.removeClass("mute");
        // Use addClass() to add "sel" to targetElement.
        targetElement.addClass("sel");
    }
    selectable.on("click", focusSelected);
</script>
<style>
    .selectable {
        /* This makes the element transparent. */
        cursor: pointer;
        background-color:gray;
    }
    .sel {
        background-color:green;
    }
    .mute {
        /* This makes the element transparent. */
        opacity:0.1;
    }
    body {
        text-align:center;
    }
</style>

<!-- Time to dive deeper into more CSS properties.  -->
<!-- Borders can be added to surround elements. -->

<style>
    /* Remember to select a class, use a "." */
    .content {
        /* To add a default border, add a border-style. */
        /* Border styles can be: solid, dotted, ... */
        /* ... inset, double, groove, ridge, outset */
        border-style:double;
    }

<!-- Margin and Padding are used to layout elements. -->
<!-- Margin is the space between elements. -->
<!-- Padding is distance between the content and... -->
<!-- ... edge of an element. -->

<style>
    body {
        text-align:center;
    }
    img {
        border:1px black solid;
    }

// Use game.randomInteger(min,max) to add randomness!
game.spawnPlayerXY("knight", 40, 35);
game.addSurviveGoal();
game.addDefeatGoal(8);

function onSpawn(event) {
    while(true) {
        var unit = event.target;
        var enemy = unit.findNearestEnemy();
        if(enemy) {
            unit.attack(enemy);
        }
    }
}

<!-- The <script> tag lets you add JavaScript! -->
<!-- The browser can only read JavaScript, not Python! -->

<script>
    // -JavaScript should be written inside <script> tags.
    // CodeCombat uses jQuery to make JavaScript easier.
    // jQuery is a function, like moveLeft().
    // Except instead of "moveLeft()", it's just: "$()"
    // Finds #theImage.
    var image = $("#theImage");
    // Setting the image's "background-color" to "red".

<!-- It is possible to make your website interactive! -->
<!-- jQuery includes ".on()" to watch for events. -->
<!-- The "click" occurs when an element is clicked. -->

<script>
    // Remember only JavaScript goes inside <script> tags.
    // This sets the button's text color to "blue".
    var button = $("#theButton");
    

// game.time to czas ,który upłyną  w grze.
game.spawnPlayerXY("guardian", 10, 35);
game.addSurviveGoal();
game.addDefeatGoal(5);

function onSpawn(event) {
    while(true) {
        var unit = event.target;
        var enemy = unit.findNearestEnemy();
        if(enemy) {
            unit.attack(enemy);
        }
    }
}