CS 105

Week 4

MP2

Build your own Instagram-like filters to transform your images

Available on CS 105 Website
Due: Tomorrow, Feb. 17, 8:00pm

Grades

Labs so far will be graded generously, if you did the lab you'll earn all the points.

Gradebook online soon, no major grades so far.

Midterm 1

Midterm 1 is Tuesday, March 3rd, 8:00pm-9:30pm

Two weeks from tomorrow!

Midterm 1

No class on Wednesday after midterm

Conflict: Wednesday, March 4th, 8:15am-9:45am
Sign-ups will be available by Wednesday

Midterm 1

25-35 Multiple Choice Questions
2-4 Free Response Questions

Practice exams will be going up on the course website

Data Types

Numbers

var num = 43;
var x = 31;

Strings

var s = "Hello, world";
var s2 = "ABC";

Functions

var square = function(x) {
  return x * x;
};

Simple Image

var pixel = img.getRGB(x, y);
img.setRGB(x, y, pixel);

Arrays

Arrays are a fancy name for a list of variables

Arrays

Define an array by putting comma-separated values within square brackets:

var a = [ 93, 97, 82 ];

Access a value by using square brackets on the array variable and giving an index:

var x = a[0];  // 93
var y = a[1];  // 97
var z = a[2];  // 82

Arrays

Array variables, like strings, have a .length property.

var a = [ 93, 97, 82 ];
var len = a.length;   // 3

Arrays

Suppose you have an array containing your grades on three assignments. What is your average grade?

var a = [ 93, 97, 82 ];

Lets program!

Arrays

Suppose there is a sale where items over $20.00 are 30% off. What is the total, after-sale price of the order?

var items = [ 10.50, 22.30, 82.13, 4.32, 53.21 ];

Lets program!

Strings

Strings can also be treated as an array of characters (one letter strings).

var s = "Illinois";
var c = s[0];  // "I"

Conditionals

We can join two Boolean expressions together with && for AND, || for OR.

if (a >= 20 && a <= 50) {
  ...
}
if (a >= 20) {
  if (a <= 50) {
    ...
  }
}

Conditionals

if (a <= 20 || a >= 50) {
  ...
}
if (a <= 20) {
  ...
}
if (a >= 50) {
  ...
}
// Will NOT work
if (20 <= a <= 50)
// ...read as:
if ((20 <= a) <= 50)

Conditionals

Lets find the vowels in Illinois