Unit 4: Day 2

START DATE:DUE DATE:STATUS:Open

Tasks

This lesson has been designed with flexibility in mind.  You can:

  • Give catch up time
  • Introduce concepts from the Theory Unit.  
  • Etc...

41.1 Ex3 - Music Festival Registration

  • Uses window.prompt which students may not have been exposed to before.  Explain that these pop up windows override the rest of the code until they are finished.
  • That is why I left Draw blank and used the mousePressed function. BUT draw is still needed to keep the program running.
  • Therefore, window.prompt boxes are to be used sparingly.  Instead, we will rely mostly on single key presses and more complex uses of the mouse.

Music Festival Registration

//Global Variables 

let name;

let year;

let age;

let instrument;

let cat;

let logo;

let angle = 0;

let formComplete = false;

function preload() {

logo = loadImage("images/musiclogo.png");

}//end preloading of images and fonts

function setup() {

let sketch = createCanvas(600, 600);

sketch.parent("mycanvas");

background(155, 135, 155);

    textSize(24);

text("Click anywhere to register for the competition.", 50, 400);

}//end setup

function draw() {

    angleMode(DEGREES);

    translate(300, 150);

    rotate(angle);

    angle++;

    if (angle > 360) {

        angle = 0;

    }

  imageMode(CENTER);

    image(logo, 0, 0);

translate(0,0);

    if (formComplete) {

        angle=0;

        noLoop();

        fill(0);

        noStroke();

        textSize(24);

        text("Competitor Name: " + name, 50, 450);

        text("Age: " + age, 50, 325);

        if (age > 21) {

            text("Division: Senior", 50, 475);

        } else if (age >= 16) {

            text("Division: Junior", 50, 475);

        } else {

            text("Division: Child", 50, 475);

        }

        if (cat === "pro") {

            text("Fee for Professionals: $100", 50, 500);

        } else {

            text("Fee for Amateurs: $30", 50, 500);

        }

    }

}//end draw

function mousePressed() {

    background(155, 135, 155);

    name = window.prompt("What is your name");

    // print("Debug: testing name variable: " + name);

    year = window.prompt("What year were you born?");

    age = 2020 - year;

    cat = window.prompt("What category pro or amateur?");

    formComplete = true;

}//end mousePressed

41.1 Boolean Quick Check #1

  • I have developed a series of Google Form Quizzes to act as formative assessments. They get successively harder as the examples progress. 
  • A copy can be found in the Resources folder 1.4  - Year 1: Programming Part 2
  • Or you can see a student version of the quiz here.
  • Have each student write down the variables at the top of the quiz on scrap paper before they begin so they do not need to scroll up and down.


Continue to Unit 4: Day 3 »