Get Tag Count
getTagCount(tagName)
that accepts a tagName
parameter and returns the number of elements on the page with that tag name. The function should use the getElementsByTagName()
method to retrieve a collection of elements with the specified tag name.Example usage:
// Given the following HTML:
// <div>Some content here</div>
// <div>Another div element</div>
// <span>A span element</span>
// <p>A paragraph element</p>
const divCount = getTagCount('div'); // divCount equals 2
const spanCount = getTagCount('span'); // spanCount equals 1
const pCount = getTagCount('p'); // pCount equals 1