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 trialSean Loke
14,659 PointsExtra Credit Both Questions- Using Arrays
Hey guys,
Anyone can help me to build the code for the extra credit (both questions) using arrays? I successfully did it using without arrays but I feel there must be a better way of fulfilling the criteria.
Thanks.
1 Answer
Anders Björkland
7,481 PointsHi Sean,
If I understood you correctly, you want all censored words to be in a String array? There are ways to make that work. I had the loop around the part where you read a line to the noun String-variable, and there you have another loop to check each of the words in the array and compare them to the noun. If there is a match I set a boolean to keep track of it. This boolean is used to determine id the outer loop should continue or not.
In pseudo code it would look like this:
- get user input for a noun
- check if the noun is legal
- have an array of illegal words
- compare noun to each illegal word
- if a match, go back to (get user input for a noun)
- have an array of illegal words
- ...continue with other parts of the program