Codecademy Ruby 1 Flashcards

1
Q

What’s a boolean?

A

A true or false statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

It’s also important to remember that Ruby is..

A

case-sensitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

never use _______ with booleans,

A

quotation marks (‘ or “) or Ruby will think you’re talking about a string (a word or phrase)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the name of this kinda thing? 2**8

A

exponentiation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s an easier way to do 222

A

2**3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s the name of the operator that returns the remainder of division?

A

Modulo

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s 25 % 7?

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s the difference between print and puts?

A

puts adds inserts a blank line after the output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Everything in Ruby is an _______ with built in ____

A

object / method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Editor>______>console

A

interpreter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Display the number of characters in ‘Tom’

A

puts “tom”.length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

method for reversing values

A

.reverse

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

method for changing case

A

.upcase and .downcase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what do you use for a multi-line comment?

A

=begin
comment
yes yes yes
=end

(no space between the = and begin. Maths is ok either way with that though)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what’s the convention for variables in Ruby?

A

lower case with _ between words, with no other symbols

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what character do you use to set variables?

A

=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

what’s do you call a positive or negative number with no decimal bit?

A

an integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

what operator do you use to call a string?

A

.

For example “string”.method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

method to get inputs

A

gets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

method to remove the line break added automatically when receiving user input

A

.chomp

21
Q

how do you print a variable into a string

A

{variable}

22
Q

what do you call when a variable is replaced with a bit of information?

A

string interpolation

23
Q

what’s the method for capitalising the first letter of a string?

A

.capitalise

24
Q

what do you use to change the value of a variable inside itself?

A

!

25
Q

a fancy word for something that has a value that evaluates to either true or false

A

expression

26
Q

the convention for spacing inside an if statement

A

two spaces (not tabs)

27
Q

use to add more options to an else/if statement

A

elsif (NOT elseif)

28
Q

in ruby, what can you use instead of checking whether something is negative using an if statement? (maybe just used for booleans?)

A

unless

for example:
unless hungry
–code

(hungry would have to be set to true for the code to execute)

29
Q

what do you use instead of = as a comparator (otherwise called a rational operator)?

A

==

30
Q

not equal to

A

!=

31
Q

greater or equal to

A

> =

32
Q

less than or equal to

A

<=

33
Q

What is a boolean operator?

A

Boolean operators result in boolean values: true or false.

34
Q

What does && do?

A

The boolean operator and, &&, only results in true when both expression on either side of && are true.

35
Q

or operator

A

||

Ruby’s or operator evaluates to true when either or both of the values are true… called an inclusive

36
Q

not true

A

!true

37
Q

what would this equate to?

!(700 / 10 == 70)

A

false

because ! is a boolean operator

38
Q

(x && (y || w)) && z

Expressions ____ parentheses are always evaluated before anything ____ parentheses.

A

Expressions in parentheses are always evaluated before anything outside parentheses.

39
Q

What are the three boolean operators in Ruby?

A

&&, || and !

40
Q

what is a float?

A

a number with a decimal

41
Q

change gets to get an integer input

A

gets.to_i

42
Q

change gets to get a float input

A

gets.to_f

43
Q

generate a random floating point number between 0 and 1

A

rand()

44
Q

generate an integer between 0 and 10

A

rand(10)

45
Q

generate an integer between 20 and 100

A

rand(20..100)

46
Q

create a while loop

A

while

end

47
Q

how to you convert an integer to a string?

A

.to_s

48
Q

how to you make the code wait for 1 sec?

A

sleep 1