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

JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Linking Around the Application

getting this error message: RangeError: Invalid status code: undefined

having some real problems with this one, cant seem to figure out what the problem is, it looks exactly like the video to me..

cards.js

router.get('/',(res,req)=>{

const numberOfCards = cards.length;

const flashCardId = Math.floor(Math.random()*numberOfCards);

res.redirect(`/cards/${flashCardId}?side=question`);

});

3 Answers

Do you use the beginning of these?

const { data } = require('../data/flashcardData.json');
const { cards } = data;

The code looks good. If this isn't your solution please show your whole code.

found the troublemaker : router.get('/',(res,req). response comes before the request..

Really, I didn't even notice :)

sneaky, sneaky code =)

How did you fix this? I can't figure it out.

I had the same problem, it ended up being because I was using math instead of Math.

router.get('/', (req, res) => {
    const numberOfCards = cards.length;
    const flashcardID = Math.floor(Math.random() * numberOfCards);
    res.redirect(`/cards/${flashcardID}?side=question`)
});