Project: Console Profile Card
Build a guided console project that stores a learner profile, formats a multi-line card, and handles a missing optional field.
By the end, you’ll be able to…
- Store related profile facts in clearly named const variables.
- Assemble a multi-line card with a template literal.
- Supply a fallback when an optional field is missing.
- Review the output against an acceptance checklist.
01Project brief
In this project you will build a profile card that prints cleanly in a browser console or a Node.js terminal. The card will present a name, a role, a location, a learning goal, and an optional website. You will store each fact in a clearly named variable, assemble the card with a template literal, and print it with one console.log call.
The project also asks you to handle missing information. A website is optional, so the card should show a useful fallback instead of the word null. Keep the work in a file named profile-card.js. Run it in either host; the output should be identical because this program uses only the shared language and console.
02Step 1: Store the profile facts
Start by naming each fact. Use const for every field because none of these values needs to be rebound while the card is built. The website is deliberately set to null, which represents an intentional absence. It is different from an empty string, which would mean that a website exists but its text is blank.
Read the declarations as a small data inventory. A future reader should be able to change the name or goal in one obvious place. Keep display formatting out of the raw values for now: location is plain text, and website is either a URL string or null.
03Step 2: Build the multi-line card
A template literal starts and ends with a backtick and can span several lines. Expressions inside the braces are evaluated and inserted into the text. That makes the card easier to read than a chain of quoted strings joined with plus signs. The line breaks you type inside the template become line breaks in the result.
For the optional website, use the nullish coalescing operator. The expression website ?? "No website yet" returns the right side only when the left side is null or undefined. An empty string would be preserved. This operator is a preview; Module 02 explains it alongside other logical operators.
04Step 3: Run the complete program
The complete program below combines the fields, the fallback, and the card. console.log receives the finished string once, so the console shows one entry containing several lines. That is different from calling console.log separately for every field.
Run the file and compare the output line by line. Check spacing after each colon, capitalization, and the fallback sentence. Then change website to a real address and run again. Only the website line should change. That is a small but meaningful regression check.
05Review and acceptance checklist
Review the project against the brief before moving on. The file should run without an error; every fact should have a descriptive const name; the card should use one template literal and one console.log; and the website line should show the fallback when website is null.
Also test a second profile with different values. Confirm that the layout still reads well and that no line depends on the length of another value. If a check fails, fix the smallest thing that explains it and rerun. A project is finished when the evidence matches the checklist, not when the code merely looks complete.
The ideas worth keeping.
- Store each profile fact in a descriptive const and keep display formatting in the card template.
- A multi-line template literal keeps the card's layout readable in source and output.
- Use a nullish fallback for optional fields, then test both the supplied and missing cases.
Make it yours.
Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.
Exercise 1: Add two fields to the card
Add favoriteLanguage with the value JavaScript and hoursPerWeek with the value 6. Insert both into the card as labeled lines and keep the website fallback working. Provide the complete program.
Explore a worked solution
const name = "Mira Chen";const role = "Frontend learner";const location = "Pune, India";const goal = "Build a study tracker";const website = null;const favoriteLanguage = "JavaScript";const hoursPerWeek = 6;const websiteText = website ?? "No website yet";const card = `PROFILE CARDName: ${name}Role: ${role}Location: ${location}Goal: ${goal}Favorite language: ${favoriteLanguage}Weekly study: ${hoursPerWeek} hoursWebsite: ${websiteText}`;console.log(card);The two new values follow the same pattern as the existing fields. Each placeholder is inserted at the line where it belongs, and the website fallback is unchanged because website is still null.
Exercise 2: Handle two missing fields
Given role = null and city = "Pune", build two lines with fallbacks so the output reads Role: Not provided and Location: Pune. Use ?? for both values.
Explore a worked solution
const role = null;const city = "Pune";const roleText = role ?? "Not provided";const cityText = city ?? "Location not provided";console.log(`Role: ${roleText}`);console.log(`Location: ${cityText}`);The null role triggers its fallback, while the non-null city is kept. The city fallback is never used here, but it protects the card if the location is later set to null.
What stayed with you?
Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.
Exercise 1: Add two fields to the card
Add favoriteLanguage with the value JavaScript and hoursPerWeek with the value 6. Insert both into the card as labeled lines and keep the website fallback working. Provide the complete program.
PROFILE CARD Name: Mira Chen Role: Frontend learner Location: Pune, India Goal: Build a study tracker Favorite language: JavaScript Weekly study: 6 hours Website: No website yet
Keep exploring.
The official references behind this lesson, when you want a second angle or the full details.
Pause. Put the pieces together.
You’ve reached the end of Getting Started with JavaScript. Before moving on, use this task to check what you can do independently.
Build a console profile card from scratch, run it, intentionally break it, and fix the error using the browser or terminal error message.
Try it in your own environment and write down the result. This is a self-check; reading completion does not evaluate your code.
Review this moduleOne lesson closer.
Reading is a start. Trying it yourself makes the connection.