-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Joe Ray #430
base: master
Are you sure you want to change the base?
Joe Ray #430
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Joe, I left a few comments for things to consider. The main thing I'd encourage you to do before mod 1 starts is re-do speckled_frogs using iteration.
end | ||
|
||
def change_protein | ||
@protein.insert("Chicken") #inserts Chicken for protein |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What data type is @protein
? I think you're looking for a different way to reassign @protein
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@protein is an object/instance variable.
puts "#{x} speckled frogs sat on a log" | ||
puts 'eating some most delicious bugs.' | ||
puts 'One jumped in the pool where its nice and cool,' | ||
puts "then there were #{y} speckled frogs." | ||
puts '' | ||
puts "#{y} speckled frogs sat on a log" | ||
puts 'eating some most delicious bugs.' | ||
puts 'One jumped in the pool where its nice and cool,' | ||
puts "then there was #{z} speckled frog." | ||
puts '' | ||
puts "#{z} speckled frog sat on a log" | ||
puts 'eating some most delicious bugs.' | ||
puts 'One jumped in the pool where its nice and cool,' | ||
puts 'then there were no more speckled frogs!' | ||
puts '-----------------------------------------------' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try re-doing this exercise using iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks. I'm going to try and finish up where I'm at in the ruby exercises then give this another go.
def encrypt(string, key) | ||
string_to_ascii_array = string.chars.map {|char| char.ord} | ||
shifted = string_to_ascii_array.map {|char| char + key} | ||
shifted.map {|char| char.chr }.join(', ') | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Never copy and paste code as your own. If work is still in progress and copied code is for reference, make a comment to that effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I have a question about this if/when you have time. I know there are usually multiple ways to solve problems but programmers typically settle on one. In situations like these are you saying it's ok to use code already written by others so long as I leave a comment saying so? Sorry I feel like this is a tricky area as I'm sure programmers use code that's already written regularly. If not, I'm sure they use code written by others as inspiration for their own. Is what you stated above your best advice for how to handle situations like these going forward?
@@ -0,0 +1,18 @@ | |||
def FizzBuzz (x,y) | |||
while x <= y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When there are assumptions around numbers, like y > x
, using variable names like max
and min
are extremely helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand and appreciate the feedback.
2. First, I defined a method called encrypt for my CaesarCipher class. Then I converted | ||
the string to an array of characters using `.chars`. Secondly, you can use `.map` | ||
to iterate through the array and find the ASCII characters using `.ord`. I now needed to | ||
shift. To do this, I used `.map` to iterate through the ASCII character codes | ||
and then added our "shift value", which I called "key". Next, using `.join` | ||
I was able to convert and join our new characters in the shifted array into | ||
a new string of characters correlated to ASCII code. I got close to the end by defining | ||
and instantiating a new object called "cipher" using the `.new` method. Lastly, | ||
I printed the encrypted message and designated that message with they argument | ||
and key(or value to be shifted). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work explaining the code in your CaesarCipher.
Here is my prework.