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 trialCassaundra West
2,720 PointsSimpler Way
if you are trying to write dry code wouldn't this be a much simpler way to output the amount of incorrect answers?
html = "You got " + correctAnswers + " right and " + (questions.length-correctAnswers) + " wrong!"; print(html);
This was just my first idea when trying to solve the quiz, is this not the best method?
1 Answer
Steven Parker
231,236 PointsBeing "DRY" doesn't mean replacing variables with calculations.
There's really nothing redundant in either implementation method, so one was isn't more "DRY" than the other.
However, in phase 2 of the program development, the objective includes retaining both the correct and incorrect questions, so you could eliminate keeping a separate count altogether and do something like this:
html = `You got ${correct.length} right and ${wrong.length} wrong!`;
I also used string interpolation via a template literal here to make it even more compact.