aboutsummaryrefslogtreecommitdiffstats
path: root/exercises.rb
blob: aee42e625cf700546036f95fab925f060167a57a (plain)
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
# Exercise 1
# Write a function called `divide` that takes 2 arguments.
# This function will divide the first argument by the second argument and return
# the result.


# Exercise 2
# Write a function called `hello5` that will print the string "hello" 5 times,
# with each "hello" on a separate line


# Exercise 3
# Write a function called `hello_x_times` that takes 1 argument which is a
# number. If the argument is 4, "hello" will be printed 4 times. Each "hello"
# must be printed on the same line (e.g. "hellohellohellohello").


# Exercise 4
# Write a function called `string_plus` that takes 2 string arguments. It will
# return a string with the second argument concatenated to the first ('working'
# and 'example' become 'workingexample').


# Exercise 5
# Write a function called `join_reverse_array` that takes 1 argument, an array
# of strings. It will return a string with each element of the array
# concatenated in reverse order (['az', 'by', 'cx', 'dw'] becomes 'dwcxbyaz').


# Exercise 6
# Write a function called `array_tack_join` that takes 2 arguments, an array of
# strings, and a string. It will concatenate the second argument to each string
# in the array and return a string with one string in the array per line (e.g.
# ['banana', 'orange', 'apple'], ' cat' would become:
# "banana cat
# orange cat
# apple cat"


# Exercise 7
# Write a class called `Table`. When initialising `Table`, a decimal height must
# be passed to the initialiser. The table instance's height can then be read and
# set using `my_table.height` and `my_table.height = 20.9`


# Exercise 8
# Copy your `Table` class and change the copy's name to `Table2`. Add a method
# `height_times2` that returns the table's height * 2.