CS 105

Week 1

Activity 0

Due: ~15 minutes ago

Office Hours

All office hours are now posted on the course website!

Scratch

Scratch: Example 1

"The Barking Dog"

Scratch: Example 2

"Tay-tay" (Taylor Swift)
(CS 105 @ UIUC, MP0 Submission, Spring 2015)

Converting Scratch to JavaScript

The "First Rule"

Every Scratch block is a JavaScript statement.

All statements tell the computer to do something.

Function Calls

Function Calls

A function call runs code somewhere else that does something else.

Examples

In Scratch, the say funciton runs code on a sprite that has it speak.

Function Calls

A function call runs code somewhere else that does something else.

Examples

In JavaScript, the alert funciton runs code in a web browser that informs the user.

alert("Hello, world!");

Function Calls

alert("Hello, world!");
alert  (  "Hello, world!"  )  ;
Run as a JsFiddle!

Variables

Variables

Variables store data in a computer's memory for later use.

Variables

var statement = "Hello, world!";
alert(statement);

Variables

var a = 3;
a = a * 3;
alert(a);

Variables

Strings vs Numbers

Variables

Use var only the first time you refer to the variable.
var a = 3;
a = a * 3;
var b = a * 10;
alert(b);

Conditionals

Conditionals

Conditionals allow the computer to make decisions based on values of variables.

Conditionals encapsulate other blocks, so they use curly braces, NOT semicolons.

var x = 10;
if (x > 5) {
  alert("x is larger than 5");
}

Scratch: Example 3

DDR
(CS 50, Harvard University)

Looking Forward: This Week

Lab 1
Final lab on Scratch!


MP0
Out now, due next Tuesday by 8:00pm


Activity 1
Out today, due next Wednesday by 11:45am

Looking Forward: Next Week

Lecture (Week 2)
Monday is Labor Day — No Lecture on Monday or Wednesday


Lab 2
First lab on JavaScript
(Activity 1 due before labs begin!)


MP1
Out on Tuesday, Sept. 8, due Sept. 15


Activity 2
Due before lecture on Sept. 14/16