Top Banner
chapter 1 communicating with your computer
34

Chapter 1: Communicating with Your Computer

May 11, 2015

Download

Software

Seth McLaughlin

Introduction to programming with JavaScript, Chapter 1.
Video version: https://www.youtube.com/watch?v=Ps03yn2XlUw

In this chapter, we explore the basics of computer programming through hands on exercises with JavaScripts.

Concepts covered:

- expressions
- statements
- values
- operators
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 1: Communicating with Your Computer

chapter 1

communicating with your computer

Page 2: Chapter 1: Communicating with Your Computer

English

French

Spanish

Chinese

Page 3: Chapter 1: Communicating with Your Computer

We talk to computers with

programming languages.

c++

Page 4: Chapter 1: Communicating with Your Computer

JavaScript

Page 5: Chapter 1: Communicating with Your Computer
Page 6: Chapter 1: Communicating with Your Computer

Chakra V8 SpiderMonkey

Page 8: Chapter 1: Communicating with Your Computer

input output

Page 9: Chapter 1: Communicating with Your Computer

input outputJavaScript Code text, behavior

Page 10: Chapter 1: Communicating with Your Computer

what is 2 + 2?

4!

Page 11: Chapter 1: Communicating with Your Computer

2 + 2;

Page 12: Chapter 1: Communicating with Your Computer

2 + 2;expression

Page 13: Chapter 1: Communicating with Your Computer

2 + 2;expression

semicolon ends the expression

Page 14: Chapter 1: Communicating with Your Computer

2 + 2;expression

semicolon ends the expression

arithmetic operator

Page 15: Chapter 1: Communicating with Your Computer

2 + 2;expression

semicolon ends the expression

arithmetic operator

value value

Page 16: Chapter 1: Communicating with Your Computer

2 + 2;evaluates to

the value 4

Page 17: Chapter 1: Communicating with Your Computer

var sum = 2 + 2;

Page 18: Chapter 1: Communicating with Your Computer

var sum = 2 + 2;expression

assignment operator

identifier

keyword to declare new variable

Page 19: Chapter 1: Communicating with Your Computer

sum;evaluates to

the value 4

Page 20: Chapter 1: Communicating with Your Computer

var sum = 2 + 2;

sum = 4 + 10; // sum now equals 14

Page 21: Chapter 1: Communicating with Your Computer

var sum = 2 + 2;

sum = 4 + 10; // sum now equals 14comment, ignored by the JavaScript engine

Page 22: Chapter 1: Communicating with Your Computer

var sum = 2 + 2;

sum = 4 + 10; // sum now equals 14

sum + 10; // evaluates to 24

Page 23: Chapter 1: Communicating with Your Computer

var sum = 2 + 2;

sum = 4 + 10; // sum now equals 14

sum = sum + 10; // sum equals 24

Page 24: Chapter 1: Communicating with Your Computer

10 - 6; // evaluates to 4

10 * 4; // evaluates to 40

10 / 2; // evaluates to 5

Page 25: Chapter 1: Communicating with Your Computer

10 - 6; // evaluates to 4

10 * 4; // evaluates to 40

10 / 2; // evaluates to 5

subtraction operator

multiplication operator

division operator

Page 26: Chapter 1: Communicating with Your Computer

Review

Page 27: Chapter 1: Communicating with Your Computer

What are the values in this expression?

1 + 45 + 10 + 20;

Page 28: Chapter 1: Communicating with Your Computer

What does this expression “evaluate” to?

99 + 1 + 10;

Page 29: Chapter 1: Communicating with Your Computer

What does this expression “evaluate” to?

// 34 + 5 + 1;

Page 30: Chapter 1: Communicating with Your Computer

What value is the variable bottles set to?

var cans = 2 + 10;

var bottles = 2 + cans - 10 - cans;

Page 31: Chapter 1: Communicating with Your Computer

Homework #1

Write a JavaScript

expression which adds

5 to 10.

This expression

should evaluate to 15.

Use www.repl.it to

write your code.

Page 32: Chapter 1: Communicating with Your Computer

Homework #2

Define three variables. One

should hold your age, one

should hold your favorite

number, and one should hold

the number of siblings you

have.

Next, define a new variable

which stores the result of

adding the previous three

variables together.

Page 33: Chapter 1: Communicating with Your Computer

Homework #3

Define a variable to hold the number

of hours in a day.

Multiply this value by 7 to get the

number of hours in a week. Assign

this to a new variable.

Next, multiply this by the number of

weeks in a year (52) and assign the

result of this in a new variable.

Finally, divide this number by the

number of days in a year (365). What is

the result?

Page 34: Chapter 1: Communicating with Your Computer

Intro to Programmingwith Seth McLaughlin