Skip to content

Conversation

@mfunkemomo
Copy link

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What went well in your code style, such as indentation, spacing, variable names, readability, etc.? What was lacking? I think I did well in spacing, indentation, and variables names but could work on readability and flow.
How did your code keep track of user input? I stored user input into 3 variables: user_operator, num1, and num2. This way I could always reuse the user input for various parts of the code.
How did your code determine what operation to perform? I used a case/when condition to determine what operation to perform. If the operator as a string matched one of the given string cases, it would perform the actual math operation and return the results.
What opportunities exist to create small methods for this project? I initially attempted to create 2 methods to check if the user input was a valid operator or number. However, my attempt did not work but I realize that these two methods are the opportunities that could reduce code lines and make code more efficient.
In the next project, what would you change about your process? What would you keep doing? I would keep the structure of my code such as having the variables and methods defined at the top and begin the code program after constant codes are set. I would change how I return/print out my results. Right now I have results printed within the calculations method but ideally, I'd like the method to return the results and I would have one line at the end of the program that would print the results (my previous attempts at this did not work).

@mfunkemomo mfunkemomo changed the title Branches - Monick K. Branches - Monick Aug 7, 2019
@tildeee
Copy link
Collaborator

tildeee commented Aug 9, 2019

Calculator

What We're Looking For

Feature Feedback
Readable code with consistent indentation x
Practices using variables appropriately x
Practices using conditionals appropriately x
If any, practices iteration appropriately x
If any, practices using custom methods appropriately x
Takes in two numbers and an operator and can perform addition x
Takes in two numbers and an operator and can perform subtraction x
The program handles divide when attempting to divide by zero x

Fantastic work on this Monick! Your code is so clean, logical, and readable, and a lot of the things you did were particularly clever and/or elegant. I'm really happy how you practiced making methods and using the case/when syntax and also iterating over a hash for displaying!

If you had more time on this, I would LOVE to see you pull the logic of getting user input and checking its validity into a method. The code that you wrote for getting both numeric input is the same! I've added a few other comments, some of them about the ! in conditionals. Let me know if you have any questions on that.

Overall, this project was GREAT! Great work!


#method for checking if value is numeric
def is_number? string
true if Float(string) rescue false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This method you defined is sooo useful and so elegant! In general, I may suggest an explicit return with return true if Float(string) rescue false, even though it ruins how elegant it looks. SORRYYY

#check to see if user is trying to divide by 0
if num2 == 0
#if num2 is 0, then tell user, not possible. That's rude and exit program.
puts "Looks like you're trying to divide by 0. You know that's mean. BYE BYE FELICIA!"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

puts "Here is a list of types of math"
operations_list.each do |key, value|
puts "#{key} (#{value})"
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so fancy and it makes me happy. Maybe consider renaming key and value to operation and symbol?

puts "What kind of math do you wanna do? "
user_operator = gets.chomp
#call on check_operator method to check if user entered a valid operation
if variations_list.include?(user_operator) == false
Copy link
Collaborator

@tildeee tildeee Aug 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to write this is if !variations_list.include?(user_operator), because the ! negates it

puts "Cool. Now, what's the first number you wanna calculate?"
user_num1 = gets.chomp
#check to see if input is valid (a number to use for computation)
if is_number?(user_num1) == false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to write this is if !is_number?(user_num1)

#create a calculator program that asks for user input and runs file from command line

#define global scope variables
results = nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally a small thing, but you named this variable results, when it never will be an array, it will always be one result. Consider renaming this to result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants