Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRyan Maneo
4,342 PointsIs it okay that mine was extremely different?
I was able to do this quite easily and with surprisingly less code and less "magic numbers"
It appears to do the same thing as his code... but I'm concerned, was I supposed to do it like he did?
My code: http://hastebin.com/ganiwedetu.pl
His code: http://hastebin.com/obaquponey.cs
Thanks for your opinions and comments,
Cheers,
βRyan
1 Answer
rh12
4,407 PointsOften in programming there are many different ways to solve the same problem. Even if your solution is not the exact same, you should think about your code in terms of readability and future maintainability.
In my review of the code that you posted, it seems that there are logical differences that would result in different outcomes if both solutions were executed side-by-side.
For easier reading lets say your code is Solution A and his code is Solution B.
Logical Differences:
- In Solution A a student with a score of 69 or less and a grade level of 12 would get the "who are your?!" message. In Solution B they would get the "summer school" message.
- In Solution A a student with the score of 70 and a grade level of 2 would get the "see you next year" message. In Solution B they would get the "Error: Grade level is not 9-12!" message.
My Opinions:
- In Solution A, score should probably be represented as a Float instead of an Int
- In Solution A, the conditions of the if statement are inconsistent. currentGrade appears before score in one else if and are switched around in another.
- Some of the numbers in both solutions could be replaced with constants (i.e. the grade levels)
- I like the intent of nextGrade in Solution A, however I think it would be better to use that code in the else if block because it is only used there.
Hope this helps :)