-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexercise1.rb
35 lines (29 loc) · 1.06 KB
/
exercise1.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
#Reverse method
puts "Charlotte".reverse
#You can't reverse a number but you can reverse a string e.g. puts 40.reverse
#Ruby throws useful error messages
puts 30.to_s.reverse
#e.g. to_s -convert values to strings
#e.g. to_i -convert values to integers
#e.g. to_a -convert values to arrays
#Length method
puts "Charlotte".length
#E.g. on a password to check correct length of password
#Repeating/multiplying strings
puts "Charlotte" * 5
#Arrays
puts [12, 47, 35].max
#Gives the highest Numbers
#Variables
ticket = [1,3,2]
#Variables store information
puts ticket.sort!
#sorts- ! means modify same array rather than make a new copy that's sorted
#Learning overview
#1. The prompt- prompted for answers
#2. Numbers & strings- maths & text objects in Ruby
#3. Methods- methods are actions, English-language methods like reverse & symbolic methods like *
#4.Ruby allows you to convert between different types using "to" methods
#5. Arrays are simply lists!
#6. Arrays store their information in a sequence
#Variables store information you might use at a later point through assignment