Unit 1: Day 11
Tasks
11.1 eCommerce Variables Example
- Discuss the progression of the credit:
- Coming up, we are going to do a couple of assignments focusing on variables and math. Therefore today we do a fairly length example that is only complex because it juggles lots of variables
- 1 new assignment each day, with the credit wrapping up on Friday
- Exam (in class project) will be on Tuesday or Wednesday next week
- Talk about the complexity of this example being harder in other languages
- Discuss ways to enter the number bought more realistically.
- Demonstrate that Window.Prompt will not work well.
- Point out the nested IF statement with the timer.
- AAP-2.I.1: Nested conditional statements, or “else if” statements, consist of conditional statements within conditional statements.
- AAP-2.I.2: If the Boolean condition of the initial conditional statement evaluates to false, then the Boolean condition of the nested conditional statement is evaluated.
Unit 1 - Example 10 - Guitar Store
let product1 = "Fender Stratocaster";
let price1 = 3050.25;
let bought1 = 0;
let product2 = "Strings";
let price2 = 12.85;
let bought2 = 0;
let total1, total2, grandTotal;
let timer = 0;
function setup() {
let sketch = createCanvas(500, 600);
sketch.parent("mycanvas");
//bought1 = window.prompt("How many?");
}
function draw() {
background(252, 186, 3);
fill(0);
noStroke();
textSize(24);
text("Couprie's Guitar Store", 80, 40);
textSize(14);
text(product1,20, 150);
text(product2,20, 180);
text("$"+ price1, 150, 150);
text("$"+ price2, 150, 180);
text(bought1, 250, 150);
text(bought2, 250, 180);
total1 = price1 * bought1;
text("$" + total1, 300, 150);
total2 = price2 * bought2;
text("$" + total2, 300, 180);
if( bought2 <= 15 ){
if(millis() > timer){ //how to make a 2 second timer
timer = millis()+1000;
bought2++;
}
}
}//end draw
function keyPressed(){
bought1 = key;
}//end keyPressed
11.2 AP CPS Concepts
- Discuss the following AP concepts if you have not done so organically
- AAP-2.C.1 Arithmetic operators are part of most programming languages and include addition, subtraction, multiplication, division, and modulus operators.
- AAP-2.C.3 The exam reference sheet provides the arithmetic operators +, -, *, /,and MOD
- AAP-2.C.4 The order of operations used in mathematics applies when evaluating expressions. The MOD operator has the same precedence as the* and / operators.
11.3 Finish Collector Card Assignment
Continue to Unit 1: Day 12 »