Framer-CoffeeScript-Javascript-FlashCards
Which character do we use for decimal numbers?
The point (not the comma)
How to insert a string
Strings come in quotation marks.
“This is a string”
‘This is also a string’
How to concatenate strings?
Using a + sign:
"My name is " + "Tessa" # => "My name is Tessa
Which type of data is this:
“40”
This is a string (because inside quotation marks)
“50” + “50”
=> “5050”
How to assign a variable?
Variables are assigned using the = operator.
What is a variable?
Variables let you assign a value to an arbitrary symbol for later reference. A variable is a box you can put values into. Any kind of value, like a string or a number.
Variables can’t…
Variables
• can’t contain spaces
• can’t start with numbers
• can’t contain punctuation or symbols other than _
What is the common naming convention for variable names?
CamelCase
How do we make a string interpolation?
a variable inside a string
We can embed the variable right in the string if we surround it with #{}
print “my favorite color is #{color}, what’s yours?”
What are boolean values?
Booleans are values that are either true or false. They’re indicated with just the words true or false without quotation marks.
myBoolean = true
Which operator do we use to indicate that two values are the same?
is or ==
What do we use to negate a condition?
To negate a condition you use the keyword “is not”. In place of “is not” you can use the shortform “isnt”.
num = 5 num isnt 10 # => true
Which syntax for conditional statements?
if/else
CoffeeScript avoids using symbols like semi-colons and parentheses. But in return, we need to follow certains rules about…
… indentation
How do we insert comments in Coffee Script?
Using #
myObjectA =
name: “Framer”
age: 12
How to target the name property here?
2 options:
myObjectA.name
myObjectA[“name”]
How do we indicate that we’re putting a function in CoffeeScript?
Using the -> arrow
checkAge()
What do the brackets mean?
The () part basically means “go”. It tells the computer “run the function in the checkAge variable”
Functions can be even more useful if we can give them values to work with. These values are called…
Parameters when creating the function.
Arguments when calling the function and assigning values to those parameters.
In CoffeeScript, we can give a function the ability to accept arguments. How do we do that?
By adding parenthesis containing the argument name before the -> sign
What are arrays?
Arrays are lists or collections of multiple items
Arrays have some built in methods (functions that they can use) for finding out information about them, like length.
fruits = [“apples”, “oranges”, “bananas”]
How to get the length of this array?
fruits.length
You can access elements in an array by their index. The index is the element’s position within the array.
But there’s a warning! Which one?
Arrays are zero-indexed.
How do we access an element in an array?
We use square brackets containing the index of the element we’re looking for.
Ex: fruits [1]
How do we add to arrays?
You can add new items to an array with the method push. push adds the item you specify to the end of the array.
Ex: fruits.push(“kiwis”)
Why arrays can be very powerful in CoffeeScript?
Because they let you repeat certain functionality over and over with different items by using loops. Loops let you do something for every item in an array.
Which method would we use to uppercase the first string elements of our fruits array?
fruits [0]. toUpperCase ()
How would we uppercase all our string elements inside our fruits array?
for fruit in fruits
fruit.toUpperCase()
What is an object?
An object is a collection of properties. In programming, a property is an association between a name and a value.
If something has properties, you can store them in an object.