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 trialOliver Statt
5,175 PointsOther solution instead of redirect also possible?
This seems to be a shorter solution instead of doing a redirect. Does it have any downsides?
const side = req.query.side || "question";
2 Answers
miikis
44,957 PointsHi Oliver,
It depends on what your app does, and what you think you might want it to do in the future. Either way is acceptable but the redirection approach will afford you greater flexibility. The concept you want to keep in mind when making decisions like this goes by the name of the Single-Responsibility Principle. Basically, you want each function you write to have only one reason to change, ever; the last thing you want is for one of your routes to be handling 17 different conditions of your app.
polentz
Full Stack JavaScript Techdegree Student 11,755 Pointsthe solution seems ok, but if you input 'hint' as value for the 'side' it would be accepted and the side value in the query won't be changed to 'question' if that is what you intended to do.
JASON LEE
17,352 PointsJASON LEE
17,352 PointsHmmm... I have learned of the DRY principle from Treehouse, but I have never heard of the Single-Responsibility Principle. Not sure why this is the first time I'm hearing of this. It's important to learn good programming habits from the start as that can save a lot of trouble and headache down the road.