-
Notifications
You must be signed in to change notification settings - Fork 52
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
Create calculator.rb #45
base: master
Are you sure you want to change the base?
Conversation
CalculatorWhat We're Looking For
Well done on this project, Sara! Your code works well and reads well. If you had more time on this project, I would encourage you to consider two things:
I've also added some comments about small suggestions on how to improve your code. That being said, you did well on this. Good work! |
|
||
# ask user to input an maths operater until its valid | ||
until math_operators.include?(math_operater) | ||
puts"Invalid math operator! Please try again." |
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 is very minor, but I like having spaces inbetween my methods and strings, so I'd like a space between puts
and the string, like puts "Invalid math operator!"
num_one = Integer(gets.chomp) | ||
rescue ArgumentError => e | ||
puts "You did not enter a a number. Try again!" | ||
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.
Hm, I'm looking at this above begin ... rescue
section. You end up having this exact logic down below, inside of an until
loop... What happens if we replace this above logic with this?
print "Please enter the first number: "
num_one = Integer(gets.chomp)
num_one = Integer(gets.chomp) | ||
rescue ArgumentError => e | ||
puts "You did not enter a a number. Try again!" | ||
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.
We will get into begin ... rescue
clauses in-depth later in the program! For now, this is an okay solution, but it may be interesting to consider what it would look like without using the begin ... rescue
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions