21.08 · Objects / Practice · 6 min
Pair each key with its value
The key changes on each iteration. Brackets must use that changing name.
Activity 8 of 9 in Objects
JavaScript Basics / 21.08
Pair each key with its value
Not started
The key changes on each iteration. Brackets must use that changing name.

Read object values through changing keys
Work through 3 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)3 steps · Saved work · Instant feedback
YOUR TURN
Read the value behind each key
Repair printObjectProperties(record) to print each own enumerable property name and its value. Use the key variable in brackets; keep the Object.hasOwn guard and source object a:1, b:2, c:3. Expected lines: a: 1, b: 2, c: 3. Do not hard-code property names or values.
a: 1 b: 2 c: 3
Keep the starting inputs. Print these lines in this order, without extra output.
Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Work in VS Code instead
Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.
function printObjectProperties(record) {
for (const key in record) {
if (Object.hasOwn(record, key)) {
console.log(key + ": " + record.key);
}
}
}
printObjectProperties({ a: 1, b: 2, c: 3 });Need a nudge?
The loop gives you a key string
key changes from a to b to c. record.key reads a property literally named key. record[key] reads the property named by the current key string.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
for...in visits enumerable string keys, including inherited ones. Object.hasOwn limits this function to the record’s own fields. The source examples are simple own-field records, so this guard preserves their output while making the intended boundary explicit.
function printObjectProperties(record) {
for (const key in record) {
if (Object.hasOwn(record, key)) {
console.log(key + ": " + record[key]);
}
}
}
printObjectProperties({ a: 1, b: 2, c: 3 });Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)Continue learning

7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in