Codecademy Ruby 1 Flashcards
What’s a boolean?
A true or false statement
It’s also important to remember that Ruby is..
case-sensitive
never use _______ with booleans,
quotation marks (‘ or “) or Ruby will think you’re talking about a string (a word or phrase)
What’s the name of this kinda thing? 2**8
exponentiation
What’s an easier way to do 222
2**3
What’s the name of the operator that returns the remainder of division?
Modulo
What’s 25 % 7?
4
What’s the difference between print and puts?
puts adds inserts a blank line after the output
Everything in Ruby is an _______ with built in ____
object / method
Editor>______>console
interpreter
Display the number of characters in ‘Tom’
puts “tom”.length
method for reversing values
.reverse
method for changing case
.upcase and .downcase
what do you use for a multi-line comment?
=begin
comment
yes yes yes
=end
(no space between the = and begin. Maths is ok either way with that though)
what’s the convention for variables in Ruby?
lower case with _ between words, with no other symbols
what character do you use to set variables?
=
what’s do you call a positive or negative number with no decimal bit?
an integer
what operator do you use to call a string?
.
For example “string”.method
method to get inputs
gets
method to remove the line break added automatically when receiving user input
.chomp
how do you print a variable into a string
{variable}
what do you call when a variable is replaced with a bit of information?
string interpolation
what’s the method for capitalising the first letter of a string?
.capitalise
what do you use to change the value of a variable inside itself?
!
a fancy word for something that has a value that evaluates to either true or false
expression
the convention for spacing inside an if statement
two spaces (not tabs)
use to add more options to an else/if statement
elsif (NOT elseif)
in ruby, what can you use instead of checking whether something is negative using an if statement? (maybe just used for booleans?)
unless
for example:
unless hungry
–code
(hungry would have to be set to true for the code to execute)
what do you use instead of = as a comparator (otherwise called a rational operator)?
==
not equal to
!=
greater or equal to
> =
less than or equal to
<=
What is a boolean operator?
Boolean operators result in boolean values: true or false.
What does && do?
The boolean operator and, &&, only results in true when both expression on either side of && are true.
or operator
||
Ruby’s or operator evaluates to true when either or both of the values are true… called an inclusive
not true
!true
what would this equate to?
!(700 / 10 == 70)
false
because ! is a boolean operator
(x && (y || w)) && z
Expressions ____ parentheses are always evaluated before anything ____ parentheses.
Expressions in parentheses are always evaluated before anything outside parentheses.
What are the three boolean operators in Ruby?
&&, || and !
what is a float?
a number with a decimal
change gets to get an integer input
gets.to_i
change gets to get a float input
gets.to_f
generate a random floating point number between 0 and 1
rand()
generate an integer between 0 and 10
rand(10)
generate an integer between 20 and 100
rand(20..100)
create a while loop
while
end
how to you convert an integer to a string?
.to_s
how to you make the code wait for 1 sec?
sleep 1