-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintro-jeremy-heath.rb
159 lines (74 loc) · 2.49 KB
/
intro-jeremy-heath.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Remember that floats are fractional numbers whereas integers are whole numbers. In Ruby, 1 and 1.0 are defined by different data types with slightly different behaviors.
# Complete the following challenges in the IRB console.
# Open the IRB terminal. Exit the terminal and reopen the terminal.
# Add, subtract, multiply, and divide integers.
# puts 7+4
# puts 9-3
# puts 2*4
# puts 8/4
# Add, subtract, multiply, and divide floats.
# puts 7.5+4
# puts 9.4-3
# puts 5/2.0
# puts 8/3.0
# # Find the remainder of dividing two numbers using the modulo operator (%).
# # puts 10 % 2
# # Divide an integer by 0.
# # puts 4/0
# # Divide a float by 0.
# # puts 7.3/0
# # Divide 0 by 0.
# # puts 0/0
# # Create a variable and assign an integer.
# age = 29
# # Calculate the variable divided by 2.
# puts age/2
# # Find the remainder of the variable when divided by 3.
# puts age % 3
# # Create another variable and assign it the integer 13.
# lucky_number = 13
# # Use the relational operators on the two variables.
# puts age < lucky_number
# # Reassign the value of one variable to be 7.
# age = 7
# puts age
# # Reassign the value of one variable to be 26 times its current value.
# age = age * 26
# puts age
# Complete the following challenges in a Ruby file.
# # Create a variable and return it in a sentence using string interpolation.
# my_name = 'Jeremy'
# p "#{my_name} is in the Foxtrot cohort"
# # Create a variable that contains a string and test some of the Ruby string methods:
# test_string = 'this is a test string'
# # .upcase
# puts test_string.upcase
# # .reverse
# puts test_string.reverse
# # .include?
# puts test_string.include?('z')
# # .capitalize
# puts test_string.capitalize
# # .delete
# puts test_string.delete('s')
# # .index
# puts test_string.index('s')
# # .swapcase
# puts test_string.swapcase
# Create an array that contains the name of at least five TV shows you enjoy.
tv_array = ['Brady Bunch', 'She Hulk', 'Wanda Vision', 'Breaking Bad', 'Dexter']
# Find the length of the array.
# puts tv_array.length
# Return the first item in the array.
# puts tv_array.first
# Return the fourth item in the array.
# puts tv_array[3]
# Permanently reverse the order of the array.
# tv_array.reverse!
# puts tv_array
# Create a new empty array for your top favorite TV shows.
new_array = []
# Using the full TV show array, add your top two favorite shows to the empty array.
new_array[0] = tv_array[0]
new_array << tv_array[1]
puts new_array