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 trial
Chris Rubio
1,643 Pointswhy is craig using double quotes instead of single quotes when initializes hits and misses in his contructor ?
why is craig using double quotes instead of single quotes when initializes hits and misses in his contructor ? the guesses are in CHAR datatypes correct ?
2 Answers
Ben Reynolds
35,170 PointsYes, the code would still work if the individual guesses were stored as strings instead of chars. I think two likely reasons for using chars instead of strings for this lesson are probably these:
- To teach students about different data types, this is a convenient exercise to demonstrate how strings and chars can work together.
- Chars are a primitive type, while strings are classes. If you know in advance that a value will only be one character, it can be more efficient to use chars vs strings in terms of memory use. Depending on how complex your program is, those little performance tweaks can really add up.
Ben Reynolds
35,170 PointsA string is essentially just a collection of characters. So even though each individual guess will be one char, the lists of hits and misses will contain several characters appended throughout the course of the game which is why he initialized those containers as strings (double quotes) at the beginning.
Chris Rubio
1,643 Pointsmmm not quite understanding this one .... so (if he wanted too ) could he declare STRING instead on CHAR on his contructor ? why would he or why wouldnt he ?