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


William Bjorn
William Bjorn
11,772 Points

Did I miss this, or did we never actually write the code that would increment / decrement the votes on the Question?

My code is just very slightly different (questions are topics, and answers are comments, and the name of the router is apiRouter instead). Nevertheless, there is no coded functionality to actually make this work. We can't just assign the new value to the votes; we can't have it being :dir (up / down), because we want it to be a number. Any thoughts?

    function(req, res, next){
        if (req.params.dir.search(/^up|down$/) === -1) {
            var err = new Error("Not found - wrong up/down vote string.");
            err.status = 404;
        } else {
            req.vote = req.params.dir;
            // console.log("Vote: "+ req.vote);

    function(req, res, next){
            // console.log("Question found!");
            req.comment.votes.save(req.vote, function(err, topic){
                if (err) return next(err);

            //problem with voting, look to earlier post requests.

    //      res.json({
    //       response: "You sent me a POST request to /vote-" + req.params.dir,
    //       topicID: req.params.tID,
    //       commentID: req.params.cID,
    //       vote: req.params.dir,
    //   });

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

IIRC if this is for the API in Node course you should have written a function in the model/schema that increments/decrements votes based on "up"/"down".