-
Notifications
You must be signed in to change notification settings - Fork 48
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
Katricia - Edges - Calculator #47
base: master
Are you sure you want to change the base?
Conversation
CalculatorWhat We're Looking For
Great job overall! This program works well, and I appreciate the way you've used whitespace and methods to break up your code. There are a few places where things could be cleaned up that I've tried to call out inline below, but in general I am quite pleased with this submission. Keep up the hard work! |
print "Second number: " | ||
second_num = gets.chomp | ||
until second_num =~ /\d/ | ||
puts number_reprompt |
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.
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?
when "divide", "/" | ||
if second_num != 0 | ||
total = divide(first_num, second_num) | ||
# If second number is zero, do not invoke method. Assign zero message to total. |
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.
Could you put this division-specific error handling code in the division method?
# Case statement to link input to defined operator method and invoke method to get total | ||
case operator | ||
when "add", "+" | ||
total = add(first_num, second_num) |
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.
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(operator, first_num, second_num)
.
# Reprompt user until input is one of operators in operator array | ||
until operator_options.include? input | ||
puts "Please input the name or symbol of a valid operator." | ||
input = gets.chomp |
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.
Nice use of .include?
here
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions