Coding Challenge: Showing a Node's Child

Apply what you have learned about DOM in this lesson.

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.

Note: Before testing your code, please run the code by pressing RUN button. Then, you can click TEST button. Otherwise, the test cases won’t pass even if the code is correct.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy