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 trialRashid Mikati
2,163 PointsCannot pass colors array to res.render
Every time I try to pass the colors array into res.render, I get an error saying that callback is not a function. I checked the documentation and it turns out that you pass in the name of the file, an object, and a callback. So how on earth did Andrew pass that array into res.render?
1 Answer
Tom Geraghty
24,174 PointsThe documentation for render looks like:
res.render(file, [optional-options, optional-callback])
Given your brief description you are saying you get an error asking for a callback when you pass in the colors parameter. My assumption is your function looks like this:
app.get('/cards', (req, res) => {
res.render('card', { cardFront: "What is four times four?", hint: "15<four x four<17" }, colors)
})
This is passing 3 parameters: card pug file, an object {} with properties to pass to the pug file, and a callback function. Each of the three are separated by a comma. What I believe you have done (without seeing your code) is include the colors property outside of the curly brackets properties object {} as above.
What you should do is include in the colors object inside of the properties object like this:
// Route for the Cards page
app.get('/cards', (req, res) => {
// Use Express locals parameter object to set props
res.render('card', { cardFront: "What is four times four?", hint: "15<four x four<17", colors })
})
Written this way there are only two parameters passed to render: the 'card' pug file, and the bracketed {} properties object. This is ok since the third (and second) parameters are optional.
Hope this helps! If not, copy in your code and we'll check it out.
Jesus Mendoza
23,289 PointsJesus Mendoza
23,289 PointsHey Rashid, can you show your code?