- Become familiar with a REPL environment
- Learn about the fundamentals of programming
- Numbers + Basic Mathematic Operations
- Data Types
- Variables
- Methods
- Logical Operations
- Open
https://repl.it/ - Please search for and choose the language
Ruby - Type in
puts "Hello, World!"+ clickrun
Note:
Talk to them about what puts does
Make sure to note that printing out words require quotation marks around the word
Mention that words are known as strings and letters are known as chars
- Read - Evaluate - Print - Loop
- Interactive computer programming environment that takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user
Note:
"Now that we have an environment we can all work in, let's get down to the basics"
- Integers vs Floats
- 1 vs 1.0
- No commas in long integers!
+,-,*,/,%/: rounds down%: modulo operation => remainder
- Order of Operations still applies!
puts 2 + 5
puts 2 - 5
puts 2 * 5
puts 2 / 5
puts 2.0 / 5.0
puts 2 % 5
puts (2+5) * 6 / 3puts 25 / 4
puts 1 / 17
puts 0 / 17
puts 24 % 5
puts 1 % 4
puts 0 % 8- Numbers
- integers, floats
- Strings
- letters, words, characters
- Boolean
true,false
- Nil
- a word to describe absence of data or emptiness
to_i=> to integerto_s=> to string
puts "5" + "5"
puts "5".to_i + "5".to_i
puts (5 + 5).to_s
puts 5.to_s + 5.to_s
puts "5" + 5
puts "5" * 5Let's say we want to print out Hello, World! three times.
puts "Hello, World!"
puts "Hello, World!"
puts "Hello, World!"Let's shorten the amount of code, by storing the string in variable
phrase = "Hello, World!"
puts phrase
puts phrase
puts phrase- A variable name consists of letters and numbers
- The first character needs to be a (lowercase) letter
- Variables must not contain spaces.
- When the name of a variable consists of multiple words, it is Ruby convention to separate the words with a
_ - The value assigned to the variable can change over time
=is the assignment operator => you can use it to assign or re-assign values to variables
- Methods are the "verbs" of Ruby. Numbers and strings are the objects or "nouns"
- When you
callorinvokea method, it does something to one or more objects - When we call a method, we always use the format
object.method- To the left of the dot is the noun, to the right of the dot is the verb
"7".to_i
42.to_s<>!==!=
Note:
Mention common mistake between = and ==
puts 2 < 5
puts 2 > 5
puts 2 == 5
puts 2 != 5
puts 5 == "5"
puts "a" < "b"
puts !true
puts !falseNote:
They will do that in their own REPL environments for slides with this title
- REPL
+,-,*,/,%- Data Types
- Variables and Methods
<,>,!,==,!=
