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 Randomize Cards

Hamzah Iqbal
seal-mask
.a{fill-rule:evenodd;}techdegree
Hamzah Iqbal
Full Stack JavaScript Techdegree Student 11,145 Points

What is the purpose of the ID?

I can't see the purpose for using the id within the templateData, that is const templateData = { id, hint };

What is the functionality of the ID, and why is it passed in as an argument?

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Without looking at it too closely it looks like the ID parameter refers to an ID field in a set of structured data that makes up the card details. It's a unique identifier for your data model.

Nick Huemmer
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nick Huemmer
Front End Web Development Techdegree Graduate 26,840 Points

The id is part of the URL for each card and refers to the specific card from the array cards in the JSON data (see below).

In this case, id is 3, as it's pulled from the card indexed at 3 from the cards array: http://localhost:3000/cards/3?side=question

Notice the id in the router method router.get('/:id', (req, res) => {

That designates what data will be pulled in for the flashcard - forming part of the URL for the card.

Hopefully that helps - looks like your question was from last summer so you've probably already figured this out...I figure I'd answer the question to help out any other students that may be reading the questions and wondering the same thing.

The flashCardData.json file:

{
    "data": {
        "title": "JavaScript Flashcards",
        "cards": [
            {
                "question": "What language are Express apps written in?",
                "hint": "It starts with a \"J\"",
                "answer": "JavaScript"
            },
            {
                "question": "What is one way a website can store data in a user's browser?",
                "hint": "They are delicious with milk",
                "answer": "Cookies"
            },
            {
                "question": "What is a common way to shorten the response object's name inside middleware?",
                "hint": "It has the same abbreviation as \"resolution\"",
                "answer": "res"
            },
            {
                "question": "How many different values can booleans have?",
                "hint": "Think: binary",
                "answer": "2"
            },
            {
                "question": "Which HTML element can contain JavaScript?",
                "hint": "It starts with an \"s\"",
                "answer": "<script>"
            }
        ]
    }
}