-
Notifications
You must be signed in to change notification settings - Fork 252
/
if_statements.rb
65 lines (50 loc) · 2.04 KB
/
if_statements.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
# 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 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 = "sunny"
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 'sunscreen'
##################
# 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
puts "I have enough money for a gumball"
puts "I don't have enough money for a gumball"
#####################
# 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 = 1
has_sauce = true