13
Operators and Expressions INTERACTIVITY WITH JAVASCRIPT 01.06 Operators and Expressions

Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Operators and Expressions

Page 2: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Statements

• We have been using statements to

execute our JavaScript code

• Statements often have expressions

• Expressions produce values

Page 3: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Expression

• So if you think back to LHS = RHS, the

LHS is a variable and the RHS is what

generates the value

• What are our tools for generating values

on the RHS?

Page 4: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Assignment Operators

Operator Example Value stored in x

= x = 5 5

= y = 12

x = y

12

Page 5: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Arithmetic Operators

Operator Example Value stored in x

+ x = 2 + 5 7

- x = 5 - 2 3

* x = 2 * 5 10

/ x = 5/2 2.5

% x = 5%2 1

Page 6: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

More Operators

Operator Example Value stored in x

++ x = 5;

x++;

6

-- x = 12;

x--

11

+= x = 2;

x+=5

7

Page 7: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

String Operators

Operator Example Value stored in x

+ x = “Hi” + “There” “HiThere”

+ x = “Hi” + 5 “Hi5”

+= x = “Hi”

x +=“There”

“HiThere”

Page 8: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Boolean Operators

Operator Example Returns

== x ==5 false

== x ==12 true

!= x !=5 true

• We can also use operators to compare values

• Assume x = 12;

Page 9: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Boolean Operators

Operator Example Returns

> x >12 false

>= x >=12 true

< x <12 false

<= x <=12 true

• Assume x = 12;

Page 10: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Boolean Operators

Operator Example Returns…

== x == “12” true

=== x === “12” false

!=== x !== 12 false

• Assume x = 12;

• You need to really stop and think about these

operators…

Page 11: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Logical Operators

Operator Example returns…

&& (15 > x) && (x > 5)

both sides must be true

true

|| (15 > x) || (x > 5)

at least one side must be true

true

! !(x == 12) false

• Assume x = 12;

Page 12: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Review

• Programming is not just about knowing

the syntax of a language

• You need to think about the logic behind

what you want to do, before you start to

code

Page 13: Operators and Expressions - WD4E · 2018. 12. 12. · Operators and Expressions INTERACTIVITY 01.06 WITH JAVASCRIPT Review • Programming is not just about knowing the syntax of

Operators and Expressions INTERACTIVITY

WITH JAVASCRIPT 01.06

Acknowledgements/Contributions

These slides are Copyright 2015- Colleen van Lent as part of

http://www.intro-webdesign.com/ and made available under a Creative

Commons Attribution Non-Commercial 4.0 License. Please maintain

this last slide in all copies of the document to comply with the attribution

requirements of the license. If you make a change, feel free to add

your name and organization to the list of contributors on this page as

you republish the materials.

Initial Development: Colleen van Lent , University of Michigan School of

Information