-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings_practice_problems.rb
More file actions
99 lines (61 loc) · 2.75 KB
/
Copy pathstrings_practice_problems.rb
File metadata and controls
99 lines (61 loc) · 2.75 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 1. Write a program that uses variables to store a first and last name, then prints the full name in one line using string concatenation (the + operator).
puts "Problem 1: "
first_name = "Jenny"
last_name = "Holt"
puts first_name + " " + last_name
# 2. Write a program that uses variables to store a first and last name, then prints the full name in one line using string interpolation (the #{} operator).
puts "Problem 2: "
first_name = "Jenny"
last_name = "Holt"
puts "#{first_name} #{last_name}"
# 3. Write a program that asks the user to input a word. If the word is "marco", print "polo".
puts "Problem 3: "
# puts "Input a word:"
# word = gets.chomp
# if word == "marco"
# p "polo"
# end
# 4. Write a program that uses variables to store three different colors, then prints out a sentence using the colors with string concatenation (the + operator).
puts "Problem 4: "
color_one = "blue"
color_two = "periwinkle"
color_three = "purple"
puts color_one + ", " + color_two + ", " + color_three
# 5. Write a program that uses variables to store three different colors, then prints out a sentence using the colors with string interpolation (the #{} operator).
puts "Problem 5: "
color_one = "blue"
color_two = "periwinkle"
color_three = "purple"
puts "#{color_one}, #{color_two}, #{color_three}"
# 6. Write a program that asks the user to enter a name. If the name is not "Santa", print "You're not Santa."
puts "Problem 6: "
# puts "Enter a name:"
# name = gets.chomp
# if name != "Santa"
# puts "You're not Santa"
# end
# 7. Write a program that uses variables to store a book's title and author, then prints out a sentence using that information with string concatenation (the + operator).
puts "Problem 7: "
book_title = "Americanah"
book_author = "Chimamanda Ngozi Adichi"
puts book_title + " " + book_author
# 8. Write a program that uses variables to store a book's title and author, then prints out a sentence using that information with string interpolation (the #{} operator).
puts "Problem 8: "
book_title = "Americanah"
book_author = "Chimamanda Ngozi Adichi"
puts "#{book_title} #{book_author}"
# 9. Write a program that asks the user to enter a password. If the password is "Joshua", the program responds "Shall we play a game?". For any other password, the program responds "Access denied"
puts "Problem 9: "
# puts "Enter a password:"
# pass = gets.chomp
# if pass == "Joshua"
# puts "Shall we play a game?"
# else
# puts "Access denied."
# end
# 10. Write a program that uses variables to store the names of three cities, then prints out a sentence using that information with string concatenation (the + operator).
puts "Problem 10: "
city_one = "Chicago"
city_two = "New York"
city_three = "LA"
puts city_one + ", " + city_two + ", " + city_three