Search⌘ K
AI Features

Coding Challenge: Showing a Node's Child

Explore how to create a showChild() function that reveals a specific child element of a DOM node by index. Understand error handling for invalid nodes and out-of-range indexes to enhance your DOM manipulation skills.

We'll cover the following...

Problem statement

Your mission here is to create a showChild() function that shows one of the children of a DOM element node. This function takes as a parameter the parent node and the child node index. Error cases like a non-element node or an out-of-limits index must be taken into account.

Note: You can fetch all children of a node by using node.children where node is a DOM object.

Coding exercise

Complete the following program to obtain the expected results. The associated HTML code is given in the HTML tab.