Variables values don't substitute in res.json call

Tell us what’s happening:
I’m having trouble getting my variables to resolve in the res.json call in this code.

When I run this code I get the following json:

{"name":"${firstName} ${lastName}"}

Am I missing something or is it just general Glitch weirdness again?

Here’s the live link to my glitch app

Your code so far

app.get("/name" , (req, res) => {
  var firstName = req.query.first;
  var lastName = req.query.last;
  res.json({name : '${firstName} ${lastName}' });

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0.

Challenge: Get Query Parameter Input from the Client

Link to the challenge:

1 Like

What happens if you replace the quotes '${a} ${b}' with backticks ` {a} {b} `

Or another way… firstName + lastName ?

Right now a string is passed. Test in node or in the console…

1 Like

@anon10002461 Well spotted! I missed that :relaxed:

The solution was using backticks not single quotes

res.json({name : `${firstName} ${lastName}` });
1 Like

You’re welcome. Honestly, I make that mistake very frequently too :upside_down_face: