-
Notifications
You must be signed in to change notification settings - Fork 0
/
Variables.rb
81 lines (71 loc) · 1.91 KB
/
Variables.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
#!/usr/bin/env ruby
myFirstVariable = "I made a variable!"
puts myFirstVariable
=begin
Define your variables below!
=end
myString="I'm programming!"
myBoolean=true
myNumber=5
puts myString
puts myBoolean
puts myNumber
x = '2'
y = x + 'n'
puts y
def self.two_fer(name=gets.chomp)#nil)
#puts name.inspect
#name=name.chomp
#puts name.inspect
#puts name.empty?#blank?
#puts name
puts "One for #{name.empty? ? name="you" : name}, one for me."
puts "One for %s, one for me." % name
end
two_fer
LAYER_PREPARATION_TIME = 2
EXPECTED_MINUTES_IN_OVEN = 40
def remaining_minutes_in_oven(actual_minutes_in_oven)
EXPECTED_MINUTES_IN_OVEN - actual_minutes_in_oven
end
def preparation_time_in_minutes(layers)
LAYER_PREPARATION_TIME * layers
end
def total_time_in_minutes(number_of_layers:, actual_minutes_in_oven:)
preparation_time_in_minutes(number_of_layers) + actual_minutes_in_oven
end
=begin
+ for addition
- for subtraction
* for multiplication
/ for division
** is used for exponents power
% is modulo
=end
numberOne = 6
numberTwo = 8
numberThree = 5
numberFour = 12
numberFive = 36
testOne = numberTwo * numberThree #fill in the blank to make this 40
testTwo = numberFive % numberOne #fill in the blank to make this 0
testThree = numberFour - numberThree #fill in the blank to make this 7
if testOne == 40 && testTwo == 0 && testThree == 7
puts true
end
myFirstString = 'I am a string!' #single quotes
mySecondString = "Me too!" #double quotes
"Hi!".length #is 3
"Hi!".reverse #is !iH
"Hi!".upcase #is HI!
"Hi!".downcase #is hi!
"Hi!".downcase.reverse #is !ih
"Happy Birthday!".include?("Happy") #is true
myString = "Hi! I am code!" #In the next line, use methods to change it.
myNewString = myString.downcase.reverse
puts myNewString
myArray = [] # an empty array
myOtherArray = [1, 2, 3] # an array with three elements
myOtherArray[3] = 4
myArray = ["Not me!", "Not me!", "Me!", "Not me!"]
puts myArray[2]