forked from smileyface525/phase_0_unit_2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_solution.rb
80 lines (47 loc) · 1.62 KB
/
my_solution.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
# U2.W5: Die Class 1: Numeric
# I worked on this challenge [by myself, with: ].
# 2. Pseudocode
=begin
# Input:
Create a sides instance variable that can be used throughout our class in all the methods.
# Output:
d = Die.new(6)
d.sides => 6
d.roll=>#random number between 1 to 6
# Steps:
=end
# 3. Initial Solution
class Die
def initialize(sides)
@sides = sides
raise ArgumentError.new("You can't make that food") if @sides < 1
end
def sides
@sides
end
def roll
1+rand(@sides)
end
end
# 4. Refactored Solution
# 1. DRIVER TESTS GO BELOW THIS LINE
die = Die.new(6)
puts die.roll
# 5. Reflection
=begin
What parts of your strategy worked? What problems did you face?
I think this was pretty simple strategy. I wanted to create a Die class that when rolled returned a random number from the sides.
Once, I did some research to learn about how to randomize a range of numbers, it was simple.
What questions did you have while coding? What resources did you find to help you answer them?
Where to put the argument error. When I came back to this the code was not running properly. It was because the Argument error was outside of the
initialize class.
What concepts are you having trouble with, or did you just figure something out? If so, what?
None
Did you learn any new skills or tricks?
Yes, randomizing numbers and creating a basic die class.
How confident are you with each of the Learning Competencies?
Very
Which parts of the challenge did you enjoy?
Researching and coding. Testing possibilities in irb.
Which parts of the challenge did you find tedious?
Debugging but not very.