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,269 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,269 Points

Really, I didn't even notice :)

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

Timothy Allen
Timothy Allen
7,842 Points

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