際際滷

際際滷Share a Scribd company logo
chapter 1
communicating with your computer
English
French
Spanish
Chinese
We talk to computers with
programming languages.
c++
JavaScript
Chapter 1: Communicating with Your Computer
Chakra V8 SpiderMonkey
http://repl.it/languages/JavaScript
input output
input output
JavaScript Code text, behavior
what is 2 + 2?
4!
2 + 2;
2 + 2;
expression
2 + 2;
expression
semicolon ends
the expression
2 + 2;
expression
semicolon ends
the expression
arithmetic operator
2 + 2;
expression
semicolon ends
the expression
arithmetic operator
value value
2 + 2;
evaluates to
the value 4
var sum = 2 + 2;
var sum = 2 + 2;
expression
assignment operator
identifier
keyword to declare
new variable
sum;
evaluates to
the value 4
var sum = 2 + 2;
sum = 4 + 10; // sum now equals 14
var sum = 2 + 2;
sum = 4 + 10; // sum now equals 14
comment, ignored by the JavaScript engine
var sum = 2 + 2;
sum = 4 + 10; // sum now equals 14
sum + 10; // evaluates to 24
var sum = 2 + 2;
sum = 4 + 10; // sum now equals 14
sum = sum + 10; // sum equals 24
10 - 6; // evaluates to 4
10 * 4; // evaluates to 40
10 / 2; // evaluates to 5
10 - 6; // evaluates to 4
10 * 4; // evaluates to 40
10 / 2; // evaluates to 5
subtraction operator
multiplication operator
division operator
Review
What are the values in this expression?
1 + 45 + 10 + 20;
What does this expression evaluate to?
99 + 1 + 10;
What does this expression evaluate to?
// 34 + 5 + 1;
What value is the variable bottles set to?
var cans = 2 + 10;
var bottles = 2 + cans - 10 - cans;
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.
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.
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?
Intro to Programming
with Seth McLaughlin

More Related Content

Chapter 1: Communicating with Your Computer