Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Linus Johansson
Linus Johansson
12,469 Points

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

Adam Beer
Adam Beer
11,314 Points

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.

Linus Johansson
Linus Johansson
12,469 Points

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

Adam Beer
Adam Beer
11,314 Points

Really, I didn't even notice :)

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`)
});