thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

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

All courses

JavaScript Basics / 21.09

Select string values for output

Not started

Print lowercase string values while leaving the student record unchanged.

More options
Rob selects John Doe and Ford as string values and prints lowercase copies while the original record remains intact.
Rob’s comic strip · Objects

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.

Expected output
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.

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.

Code example
example.jsjavascript · example
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.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

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

ONE STEP FORWARD

Choose a named property first, then follow the shape of its value.