CSE 115 Introduction to Computer Science I Announcements Anyone - - PowerPoint PPT Presentation

cse 115
SMART_READER_LITE
LIVE PREVIEW

CSE 115 Introduction to Computer Science I Announcements Anyone - - PowerPoint PPT Presentation

CSE 115 Introduction to Computer Science I Announcements Anyone can do lab exam make-up. We will take the higher of the two grades. Announcements UTAs will provide a blank sheet of paper * to those who request it during lab exams. UTAs will


slide-1
SLIDE 1

CSE 115

Introduction to Computer Science I

slide-2
SLIDE 2

Announcements

Anyone can do lab exam make-up. We will take the higher of the two grades.

slide-3
SLIDE 3

Announcements

UTAs will provide a blank sheet of paper* to those who request it during lab exams. UTAs will NOT provide pens/pencils. You may NOT bring your own paper.

*but not for lab exam 1, to be fair to those who already took it.

slide-4
SLIDE 4

Announcements

  • Prof. Alphonce goofed.

Each lab exam question is worth 1/3. The weighting should have been 1/2, 1/4, 1/4. Most students are scoring 80/80: no impact. We will fix this, but after last lab: we avoid changing the grading code when live unless necessary.

slide-5
SLIDE 5

Road map

▶︎ Review ◀ miscellaneous (type names, questions from Monday) control flow JavaScript on codenvy.io

slide-6
SLIDE 6

JavaScript

expressions/variables/assignment

Simple expressions: Literals (null, true, false, 17.375, 'foo', "bar", undefined) All numbers are floating point.

Boolean literals are written all lowercase (true and false) in JavaScript, unlike Python which uses True and False.

slide-7
SLIDE 7

JavaScript

expressions/variables/assignment

Compound expressions: binary: expression operator expression unary: operator expression or expression operator

Also: a function call is a compound expression: name(expression, expression, …)

slide-8
SLIDE 8

JavaScript

expressions/variables/assignment

Some binary operators: arithmetic: +, -, *, /, %, ** string: + relational: <, <=, >, >=, ==, != Boolean (short circuiting): &&, ||

Python: and, or JavaScript: &&, ||

slide-9
SLIDE 9

JavaScript

expressions/variables/assignment

Some unary operators: arithmetic: +, - Boolean: !

Python: not JavaScript: !

slide-10
SLIDE 10

JavaScript

expressions/variables/assignment

Variables must be declared before use, and statements end with ';' var x; x = 13; var y = 17;

slide-11
SLIDE 11

JavaScript

defining and calling functions

Functions have same parts: header + body def area(w, h): return w * h function area(w, h) { return w * h; } Javascript return statement Python return statement

slide-12
SLIDE 12

Printing

console.log( 3 * 5 ); print( 3 * 5 )

slide-13
SLIDE 13

Road map

Review ▶︎ miscellaneous (type names, questions from Monday) ◀ control flow JavaScript on codenvy.io

slide-14
SLIDE 14

Extra slide: this came up during class

Delimiter names ( ) are parentheses (singular: parenthesis) [ ] are brackets { } are braces The first of each pair is an opening or left delimiter, the second is a closing or right delimiter.

slide-15
SLIDE 15

Extra slide: this came up during class

Comments # This is a Python single-line comment // This is a JavaScript single-line comment /* This is a JavaScript comment that spans many lines. */

slide-16
SLIDE 16

Extra slide: this came up during class

Additional Operators

= == === && || ! & | ~ assignment equality under type conversion ("loose" equality) equality without type conversion ("strict" equality) logical AND logical OR logical NOT bitwise AND bitwise OR bitwise NOT

We'll explain these operators (and what we mean by type conversion) later.

slide-17
SLIDE 17

Type names

The types we've seen (there are more!) bool str int float Boolean String Number

slide-18
SLIDE 18

Type names

A few more (we'll see even more later) bool str int float None Boolean String Number Null Undefined

slide-19
SLIDE 19

Road map

Review miscellaneous (type names, questions from Monday) ▶︎ control flow ◀ JavaScript on codenvy.io

slide-20
SLIDE 20

Type names

A few more (we'll see even more later) bool str int float None Boolean String Number Null Undefined

slide-21
SLIDE 21

Sequence

As in Python, statements in Javascript are executed in sequence, unless control flow is altered.

{ var x = 4; var y = 5; console.log("x + y has value " + (x+y)); } Good order: variables are declared and initialized before use.

slide-22
SLIDE 22

Sequence

As in Python, statements in Javascript are executed in sequence, unless control flow is altered.

{ console.log("x + y has value " + (x+y)); var x = 4; var y = 5; } Bad order: variables are used before declaration/initialization.

slide-23
SLIDE 23

Selection

As in Python, control flow can be altered based on the

  • utcome of a decision.

JavaScript if / if-else statement

slide-24
SLIDE 24

Selection

if statement

if ( expression ) { statement ; statement ; ... statement ; }

slide-25
SLIDE 25

Selection

if statement

if ( expression ) { statement ; statement ; ... statement ; }

if is a keyword

slide-26
SLIDE 26

Selection

if statement

if ( expression ) { statement ; statement ; ... statement ; }

parentheses are required

slide-27
SLIDE 27

Selection

if statement

if ( expression ) { statement ; statement ; ... statement ; }

expression must have a Boolean value

slide-28
SLIDE 28

Selection

if statement

if ( expression ) { statement ; statement ; ... statement ; }

a code block ('then' clause)

slide-29
SLIDE 29

Selection

if-else statement

if ( expression ) { statement ; statement ; ... statement ; } else { statement ; statement ; ... statement ; }

slide-30
SLIDE 30

Selection

if-else statement

if ( expression ) { statement ; statement ; ... statement ; } else { statement ; statement ; ... statement ; }

else is a keyword

slide-31
SLIDE 31

Selection

if-else statement

if ( expression ) { statement ; statement ; ... statement ; } else { statement ; statement ; ... statement ; }

else does not take an expression

slide-32
SLIDE 32

Selection

if-else statement

if ( expression ) { statement ; statement ; ... statement ; } else { statement ; statement ; ... statement ; }

a code block ('else' clause)

slide-33
SLIDE 33

Selection

nesting

if ( expression ) { ... } else if ( expression ) { ... } else if ( expression ) { ... } else { ...

there is no elif keyword

slide-34
SLIDE 34

JavaScript

  • n codenvy.io

To code along:

  • 1. Create a workspace with 'node-defaut' stack
  • 2. Create custom run command:

cd ${current.project.path} && node hello.js

  • 3. You should have only two workspaces (one for Python, one

for JavaScript)

  • 4. Organize your work using multiple projects within your

workspace

slide-35
SLIDE 35

Small group interactive exercise in Prof. Alphonce's sections

Define a function in JavaScript that takes a temperature as input and returns "cold" if the input is less than 65, "hot" if it is greater than 85, and "comfortable"

  • therwise.