JOBSEEKER?

A Mathematics tutoring web application for kids has a button that highlights all even numbers (in span), using 'yellow' as the background color. Clicking the button again removes the background. All further clicks add or remove the 'yellow' background alternately.

Currently, the button doesn't work as expected. For the given HTML markup and JavaScript function, select all options that will identify and fix the bugs in the JavaScript function:

<div id='numbers'>
 <span>1</span><span>2</span><span>3</span><span>4</span><span>5</span>
 <button id='btn' onclick='toggleEvenColor()'>Toggle even number highlighting</button>
</div>
1: function toggleEvenColor() {
2:   let spanElements = document.querySelectorAll('#numbers span');
3:   spanElements.forEach(function() {
4:     item.style.backgroundColor = 'transparent';
5:   });
6: }

(Select all acceptable answers.)

At line number 2, use let spanElements = document.querySelector('#numbers span:nth-child(2n)');
At line number 2, use let spanElements = document.querySelectorAll('#numbers span:nth-child(2n)');
At line number 2, use let spanElements = document.getElementsByTagName('span');
At line number 3, define item as a parameter for the anonymous function passed in forEach.
At line number 3, define event as a parameter for the anonymous function passed in forEach.
At line number 4, use item.style.background = 'yellow';
At line number 4, use item.style.backgroundColor = item.val() / 2 === 0 ? 'yellow' : 'transparent';
At line number 4, use item.style.backgroundColor = item.style.backgroundColor !== 'yellow' ? 'yellow' : 'transparent';
   

Tags
JavaScript Attribute manipulation Bug fixing Selectors Styling New Public
Easy

5min

Would you like to see our other questions?

We have 1000+ premium hand-crafted questions for 50+ job skills and 20+ coding languages. We prefer questions with small samples of actual work over academic problems or brain teasers.

Visit our question library
Private Concierge

Send us an email with an explanation of your testing needs and a list of candidates. We will create an appropriate test, invite your candidates, review their results, and send you a detailed report.

Contact Private Concierge

On the TestDome Blog

Screening Applicants: The Good, the Bad and the Ugly

Since we’re all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they’ve been screening people for many years, so they must know how to do it right?

Not really. I was surprised to discover that many experts disagree with each other. Everybody praises their pet method and criticizes the others. Many of these methods look legitimate, but are based on...

Dashboard Start Trial Sign In Home Tour Tests Questions Pricing For Jobseekers