Q: 10
Given the JavaScript below:
01 function filterDOM (searchString) {
02 const parsedSearchString = searchString && searchString.toLowerCase() ;
03 document.quesrySelectorAll(‘ .account’ ) . forEach(account => (
04 const accountName = account.innerHTML.toLOwerCase();
05 account. Style.display = accountName.includes(parsedSearchString) ? /*Insert
code*/;
06 )};
07 }
Which code should replace the placeholder comment on line 05 to hide accounts that do
not match the search string?
Options
Discussion
Option B. The question tries to trip you up with the casing on 'Block', but browsers handle it fine and 'none' is what actually hides the element in CSS. A is wrong because 'name' isn’t a display value.
I get why some might pick C, but
display only accepts 'block' or 'none' to actually show or hide. Using 'visible' or 'hidden' isn't valid for display property, that's for visibility. Pretty sure it's B but open to correction.C/D? If you use
'visible' and 'hidden' for the display property, that technically might still hide or show something in older browsers or with some odd engine, right? Not super common but maybe possible.B. not A. Similar question on practice exams, the key is that 'none' actually hides the element, and 'Block' (even wrong case) works. C and D are tricks since those aren't valid display values.
Case sensitivity doesn't break this in browsers, so B.
Its C. I thought using 'visible' and 'hidden' would be enough to show or hide the accounts, just like toggling their visibility property. Maybe I'm missing something about display here, but C looked right to me since it changes how the element is shown. Could be a trick though?
B , since 'block' and 'none' are the right display values for showing or hiding elements via JS. Even though the case is off, browsers handle it fine. I'd double check official documentation and maybe do a quick hands-on lab, just to be sure.
B tbh. The display property uses 'block' to show and 'none' to hide, so B fits even if the case is off. C and D mess with visibility not display, so they'd break the code. Pretty sure B is what they'd score as correct.
C/D? D just uses 'hidden' and 'visible', which are for visibility not display, so pretty sure that's there to trip you up. B is the actually working combo on a similar question I saw.
Tricky since 'Block' isn’t the standard case, but browsers still render it. So B.
Be respectful. No spam.