-
Notifications
You must be signed in to change notification settings - Fork 0
/
section2ex1.rb
77 lines (60 loc) · 2.26 KB
/
section2ex1.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
# In the below exercises, write code that achieves
# the desired result. To check your work, run this
# file by entering the following command in your terminal:
# `ruby section2/exercises/if_statements.rb`
# Example: Using the weather variable below, write code that decides
# what you should take with you based on the following conditions:
# if it is sunny, print "sunscreen"
# if it is rainy, print "umbrella"
# if it is snowy, print "coat"
# if it is icy, print "yak traks"
weather = 'snowy'
if weather == 'sunny'
p "sunscreen"
elsif weather == 'rainy'
p "umbrella"
elsif weather == 'snowy'
p "coat"
elsif weather == 'icy'
p "yak traks"
else
p "good to go!"
end
# Experiment with manipulating the value held in variable 'weather'
# to print something other than 'coat'
##################
# Using the num_quarters variable defined below, determine
# if you have enough money to buy a gumball. A gumball costs
# two quarters.
# Right now, the program will print
# out both "I have enough money for a gumball" and
# "I don't have enough money for a gumball". Write a
# conditional statement that prints only one or the other.
# Experiment with manipulating the value held within num_quarters
# to make sure both conditions can be achieved.
num_quarters = 0
if num_quarters >=2
puts "I have enough money for a gumball"
else
puts "I don't have enough money for a gumball"
end
#####################
# Using the variables defined below, write code that will tell you
# if you have the ingredients to make a pizza. A pizza requires
# at least two cups of flour and sauce.
# You should be able to change the variables to achieve the following outputs:
# If cups_of_flour = 1 and has_sauce = true, print "I cannot make pizza"
# If cups_of_flour = 5 and has_sauce = false, print "I cannot make pizza"
# If cups_of_flour = 2 and has_sauce = true, print "I can make pizza"
# If cups_of_flour = 3 and has_sauce = true, print "I can make pizza"
# Experiment with manipulating the value held within both variables
# to make sure all above conditions output what you expect.
cups_of_flour = 4
has_sauce = false
if cups_of_flour < 2
puts "I cannot make pizza."
elsif cups_of_flour >= 2 && has_sauce
puts "I can make pizza"
else
puts "I cannot make pizza."
end