Layla_Edges_Calculator.rb#49
Conversation
CalculatorWhat We're Looking For
Good work overall. This program works well, and I like the way you've broken up your code with withespace - this makes it much easier to read. I would definitely like to see you working with methods more - make sure you take the opportunity to practice with these as we work through the data transformation worksheet and RideShare. Other than that I am pretty happy with this submission - keep up the hard work. |
| # verifies if user enters in one of the defined options and if not, asks the user to re-enter their choice. | ||
| until %[add + subtract - multiply * divide /].include?(user_input) | ||
| print "Your input is invalid. Please try again. " | ||
| user_input = gets.chomp |
There was a problem hiding this comment.
You've written almost exactly the same code here twice, to get the first number and the second number. Could you DRY that up by putting this logic in a method?
| # which operator is selected, the calculation is completed and displayed for the user. | ||
| case user_input | ||
|
|
||
| when "add", "+" |
There was a problem hiding this comment.
This code isn't repeated, but I think it would still increase readability to wrap this case/when section in a method. That would clearly delineate where it starts and ends, and make it explicit what data it needs to work. The method signature might be something like perform_calculation(user_input, first_number, second_number).
|
|
||
| # prompts the user to select which operator option they'd like to use. | ||
| print "Please choose one operator (name or symbol): " | ||
| user_input = gets.chomp |
There was a problem hiding this comment.
I think there might be a more specific name for this variable than user_input, since there are several pieces of user input in this program. Something like operation might be a better choice.
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions