21.09 · Objects / Practice · 6 min
Select string values for output
Print lowercase string values while leaving the student record unchanged.
Activity 9 of 9 in Objects
JavaScript Basics / 21.09
Select string values for output
Not started
Print lowercase string values while leaving the student record unchanged.

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
Print string values in lowercase
Repair printStringFields(record). For each own top-level field whose VALUE is a string, print that value in lowercase. Keep the student data unchanged and keep the own-property/type guards. Expected lines: john doe and ford. Do not print key names, age, false, arrays or nested score values; do not recursively descend into them.
john doe ford
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 printStringFields(record) {
for (const key in record) {
if (Object.hasOwn(record, key) && typeof record[key] === "string") {
console.log(key.toLowerCase());
}
}
}
const student = {
name: "John Doe",
age: 16,
scores: { maths: 74, english: 63, science: 85 },
favoriteSubjects: ["maths", "science"],
hasPet: false,
vehicle: "Ford",
};
printStringFields(student);Need a nudge?
Key names and values are different
Every key here is text, but the values have different types. The guard checks typeof record[key]. The output must also read record[key], then call toLowerCase on that string value.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
The source asks to convert strings to lowercase, but its final code prints lowercase copies rather than assigning them back. This companion follows that behavior: student.name stays John Doe and vehicle stays Ford. The loop skips arrays, nested objects, numbers and Booleans.
function printStringFields(record) {
for (const key in record) {
if (Object.hasOwn(record, key) && typeof record[key] === "string") {
console.log(record[key].toLowerCase());
}
}
}
const student = {
name: "John Doe", age: 16,
scores: { maths: 74, english: 63, science: 85 },
favoriteSubjects: ["maths", "science"],
hasPet: false, vehicle: "Ford"
};
printStringFields(student);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