Skip to content

Conversation

@gracexinran
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? Variable names and spacing. Lacking: looks too crowd
How did your code keep track of user input? Assign each input to meaningful variables
How did your code determine what operation to perform? Input operation symbol or name
What opportunities exist to create small methods for this project? Display the operators as each time the input is invalid user has to select the operator again.
In the next project, what would you change about your process? What would you keep doing? Pseudocode first to avoid missing something. I'll keep making my codes work for most of conditions.

@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

Well done on this project, Xinran!

I think that your code is very organized, readable, and logical. You have a great solution for calculator, and you did a lot of nice, clever things. Your conditionals, loops, and methods look great!

If you had more time on this project, I may suggest looking over your code to see that there are more opportunities for methods to be pulled out. For example, getting the user input for the two numbers is some repeated code. I've also left some comments with other small suggestions.

Overall, your code looks great! I really love the methods you pulled out and how you organized the code and your use of the cool array things, like .include and .join. Well done!


puts "What is your first number?"
first_number = gets.chomp
while first_number.to_i.to_s != first_number && first_number.to_f.to_s != first_number # verify if the input is valid, both integer and float should be valid
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice strategy!

perform_calculation_two_numbers(operator, first_number, second_number)
end

def calculator_methods_display
Copy link
Collaborator

Choose a reason for hiding this comment

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

I LOVE that you created a separate method used to display information! Keep doing things like this!

perform_calculation_two_numbers(operator, first_number, second_number)
end

def calculator_methods_display
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer my methods to have names that are like actions (so, method names that start with verbs). I may suggest renaming this method to display_calculator_methods or show_calculator_methods, just like how you named a method perform_calculation_two_numbers

puts "Your calculation is #{num1}^#{num2} = " + "#{exponent_display}" + " = #{result}"
elsif num2 < 0
exponent_arr = [] # create an array to store num2 num1s
(-num2).to_i.times do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here, you deal with the case such that if num2 is negative, you say to take the -num2 of it. Instead of making num2 negative, could you consider taking the absolute value of num2? You can do that in Ruby using .abs, so here, consider:

(num2.abs).to_i.times do
  exponent_arr << num1
end

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