-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby_practice.rb
More file actions
79 lines (69 loc) · 1.72 KB
/
ruby_practice.rb
File metadata and controls
79 lines (69 loc) · 1.72 KB
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
#enter ruby practice
puts "Write here..."
text = gets.chomp
word = text.split {" "}
word.reverse!
#Creeate a small number inputting function.
#Link each inputted number to the 12 Days of Christmas
#Step one, this is defining N as the number inputted by the user (gets),
#it is then removing any whitespace with strip.
#finally it is converting the user input into a number (to_i)
N = gets.strip.to_i
if
( N%2==1 || N>5 && N <= 20)
puts "Weird"
else
puts "Not Weird"
end
#this is not working on Interactive Ruby... work out why
def number(N)
N =gets.strip.to_i
if
( N%2==1 || N>5 && N <= 20)
puts "Weird"
else
puts "Not Weird"
end
end
#test this with a string
Name = gets.strip.to_s
if
(Name==Lottie || Name==Laura || Name==Nat || Name==Izzie)
puts "Lived in my House 2014"
else
puts "Were not lucky enough to live in my house"
end
#now test this on the 12 Days of Christmas idea
print "Integer please: "
N = Integer(gets.chomp)
if
(N==1)
puts "A Partridge in a Pear Tree"
(N==2)
puts "Two Turtle Doves"
(N==3)
puts "Three French Hens"
(N==4)
puts "Four Calling Birds"
(N==5)
puts "Five Gold Rings"
(N==6)
puts "Six Geese a-laying"
(N==7)
puts "Seven Swan a-swimming"
(N==8)
puts "Eight Maids a-Milking"
(N==9)
puts "Nine Ladies Dancing"
(N==10)
puts "Ten Lords a-leaping"
(N==11)
puts "Eleven Pipers Pipiing"
(N==12)
puts "Twelve Drummers Drumming"
else
puts "This is simply not a day of Christmas."
end
#Now work out how to link this to the HTML file to produce graphics as numbers are inputted
<%= link_to(@album) do %>
<% end %>