chapter 1: communicating with your computer
DESCRIPTION
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 - operatorsTRANSCRIPT
![Page 1: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/1.jpg)
chapter 1
communicating with your computer
![Page 2: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/2.jpg)
English
French
Spanish
Chinese
![Page 3: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/3.jpg)
We talk to computers with
programming languages.
c++
![Page 4: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/4.jpg)
JavaScript
![Page 5: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/5.jpg)
![Page 6: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/6.jpg)
Chakra V8 SpiderMonkey
![Page 7: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/7.jpg)
http://repl.it/languages/JavaScript
![Page 8: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/8.jpg)
input output
![Page 9: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/9.jpg)
input outputJavaScript Code text, behavior
![Page 10: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/10.jpg)
what is 2 + 2?
4!
![Page 11: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/11.jpg)
2 + 2;
![Page 12: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/12.jpg)
2 + 2;expression
![Page 13: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/13.jpg)
2 + 2;expression
semicolon ends the expression
![Page 14: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/14.jpg)
2 + 2;expression
semicolon ends the expression
arithmetic operator
![Page 15: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/15.jpg)
2 + 2;expression
semicolon ends the expression
arithmetic operator
value value
![Page 16: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/16.jpg)
2 + 2;evaluates to
the value 4
![Page 17: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/17.jpg)
var sum = 2 + 2;
![Page 18: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/18.jpg)
var sum = 2 + 2;expression
assignment operator
identifier
keyword to declare new variable
![Page 19: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/19.jpg)
sum;evaluates to
the value 4
![Page 20: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/20.jpg)
var sum = 2 + 2;
sum = 4 + 10; // sum now equals 14
![Page 21: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/21.jpg)
var sum = 2 + 2;
sum = 4 + 10; // sum now equals 14comment, ignored by the JavaScript engine
![Page 22: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/22.jpg)
var sum = 2 + 2;
sum = 4 + 10; // sum now equals 14
sum + 10; // evaluates to 24
![Page 23: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/23.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/24.jpg)
10 - 6; // evaluates to 4
10 * 4; // evaluates to 40
10 / 2; // evaluates to 5
![Page 25: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/25.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/26.jpg)
Review
![Page 27: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/27.jpg)
What are the values in this expression?
1 + 45 + 10 + 20;
![Page 28: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/28.jpg)
What does this expression “evaluate” to?
99 + 1 + 10;
![Page 29: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/29.jpg)
What does this expression “evaluate” to?
// 34 + 5 + 1;
![Page 30: Chapter 1: Communicating with Your Computer](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/30.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/31.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/32.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/33.jpg)
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](https://reader033.vdocument.in/reader033/viewer/2022052522/554f9f7eb4c905ad218b4961/html5/thumbnails/34.jpg)
Intro to Programmingwith Seth McLaughlin