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 trialLinus Johansson
12,469 Pointsgetting 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
11,314 PointsDo 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
12,469 Pointssneaky, sneaky code =)
Victoria Medley
17,085 PointsHow did you fix this? I can't figure it out.
Timothy Allen
9,854 PointsI 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`)
});
Linus Johansson
12,469 PointsLinus Johansson
12,469 Pointsfound the troublemaker : router.get('/',(res,req). response comes before the request..
Adam Beer
11,314 PointsAdam Beer
11,314 PointsReally, I didn't even notice :)