Example Activities

Activities are mostly concise reminders of concepts and such from the reading, along with little exercises and such.

Exercises

A key thing we want with activities files is something marked as an exercise. Like this:

Introduction Activity

  • introduce yourself to your neighbor
  • learn their name
  • have a nice chat

Hidden Stuff

Another thing we want to be able to do is to have things that are hidden from the students until I'm ready to reveal.

Question: what is the most important part of the grading?

The project is the largest component of the semester grade.

Question: How can I write a function that greets the user?

function say_hi() {
    alert('hi');
}

say_hi();

Can I wrap an include?

// Code for Exercises 1 and 2

var mainColors = ["red","green","blue","yellow","cyan","magenta"];
var currColorIndex = 0;

function nextColor() {
    currColorIndex++;
    if( currColorIndex > mainColors.length - 1 ) {
        currColorIndex = 0;
    }
    return mainColors[currColorIndex];
}

function setNextColor() {
    var color = nextColor();
    $("#colorList li").css("color",color);
}

$("#nextColorButton").click(setNextColor);

$("#colorMenu").change(
    function () {
        $("#colorList li").css("color", $("#colorMenu").val());
    });

$("#colorName").change(
    function () {
        var extraColor = $("#colorName").val();
        $("#colorList").append("<li>"+extraColor+"</li>");
        $("#colorList li").css("color", extraColor);
    });

Executable Snippets

It would be cool to be able to execute some JavaScript that is also nicely fontified.

function say_hi() {
    alert('hi');
}

say_hi();

This does work, thought I don't see how. If it breaks, but I can see two possibilities:

  1. have students use the "copy to clipboard" button to copy the code to the JS console to execute it. Slightly tedious, but maybe a little less magical. It also means we could use console.log() instead of alert() and there aren't any namespace issues.
  2. Implement something like the copy to clipboard button that executes the code. MDN does this, doesn't it?