PencilCoder

Comparison Operators!

Goals:

  • Use comparison operators to compare numeric values and make your program react to its current state

Coding Snippets:

  • coding snippets
  • Compare numeric values using the comparison operators >, >=, <, <=, ==, and !=. The result of each of these operations will be a Boolean value which can be used as input in an if statement.
  • distance returns the distance from a sprite to a coordinate or to another sprite.
  • t.direction() returns sprite t's current bearing (e.g., 0 for "north", 90 for "east").

Math and Computer Concepts:

  • As in most coding languages, CoffeeScript uses = as an assignment operator. Hence x=5 assigns (i.e., sets) the variable x to 5.
  • The comparison operator == is used to test for equality. x==5 tests whether the value referenced by the variable x equals 5.
  • The operator != tests for inequality.  x!=5 evaluates to true when x is not assigned the value 5.
  • distance and direction return information about the current state of animation. Precede calls to these functions with await done defer() to ensure that they are evaluated in the right place.

Activities:

Save each of the following in a folder called ComparisonOps.