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

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