Challenge - 5 Problems
Template Engine Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the rendered output of this Express template?
Given the following Pug template and Express route, what will be the HTML output sent to the browser?
Express
app.get('/greet', (req, res) => { res.render('greet', { name: 'Alice' }); }); // Pug template 'greet.pug': // h1 Hello #{name}! // p Welcome to our site.
Attempts:
2 left
💡 Hint
Remember that Pug replaces #{variable} with the value passed in render locals.
✗ Incorrect
The Pug template uses #{name} to insert the value of 'name' from the render call. Since 'Alice' is passed, it outputs 'Hello Alice!'.
📝 Syntax
intermediate2:00remaining
Which option correctly sets EJS as the template engine in Express?
Choose the correct code snippet to configure Express to use EJS templates located in the 'views' folder.
Attempts:
2 left
💡 Hint
The default views folder is './views' and setting 'view engine' to 'ejs' enables EJS.
✗ Incorrect
Option A correctly sets the view engine to 'ejs' and the views folder to './views'. Other options either set wrong folders or engine names.
🔧 Debug
advanced2:00remaining
Why does this Handlebars template render '{{name}}' literally instead of the value?
Express route:
app.get('/user', (req, res) => {
res.render('profile', { username: 'Bob' });
});
Handlebars template 'profile.hbs':
User: {{name}}
Attempts:
2 left
💡 Hint
Check if the variable names in the template match the keys in the data object.
✗ Incorrect
The template tries to render {{name}}, but the data passed has 'username'. Since 'name' is undefined, Handlebars outputs it literally.
❓ state_output
advanced2:00remaining
What is the output of this EJS template with conditional rendering?
Express route:
app.get('/status', (req, res) => {
res.render('status', { loggedIn: false });
});
EJS template 'status.ejs':
<% if (loggedIn) { %>
Welcome back!
<% } else { %>Please log in.
<% } %>Attempts:
2 left
💡 Hint
Look at the value of 'loggedIn' and which block runs in the EJS template.
✗ Incorrect
Since loggedIn is false, the else block runs, rendering '
Please log in.
'.🧠 Conceptual
expert2:00remaining
Which statement best describes how template engines improve Express app development?
Select the most accurate explanation of the role of template engines in Express.
Attempts:
2 left
💡 Hint
Think about how templates combine data and HTML on the server.
✗ Incorrect
Template engines let you write HTML with placeholders and JavaScript logic to create dynamic pages before sending them to the browser.