hardMultiple Choice
FC0-U71 Practice Question: A web application uses a JavaScript function to…
A web application uses a JavaScript function to validate user input on a registration form. The function checks that the password is at least 8 characters long and contains a number. When a user submits the form with a password "abc123", the validation passes even though the password has only 6 characters. The developer examines the code and finds that the function uses the condition: if (password.length >= 8 || /\d/.test(password)). Which logical error is causing this bug?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The condition uses OR instead of AND.
The condition uses OR (||) instead of AND (&&), so the validation passes if either condition is true. "abc123" has a number, so it passes. The regular expression is correct, length check is appropriate, and the function is called.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
The condition uses OR instead of AND.
Why this is correct
The OR operator makes the condition true when either test passes, so "abc123" satisfies the digit check despite failing the length check. Replacing OR with AND would require both the eight-character minimum and a number, fixing the validation bug.
- ✗
The function is not called.
Why it's wrong here
The function clearly runs, since validation returns a pass for 'abc123'. This is tempting when a form bypasses validation entirely, but here the logic executes and returns true. A missing call would mean no validation output at all, not an incorrect pass.
- ✗
The regular expression is incorrect.
Why it's wrong here
The regular expression /\d/ correctly tests for a digit, so it is not the fault. The bug is the || operator, which makes the condition pass when either check succeeds; && is required so both length and digit rules must hold. The regex is tempting because validation logic often fails there, but here it works as intended.
- ✗
The length check is incorrect because it uses >= instead of >.
Why it's wrong here
Using >= correctly enforces 'at least 8 characters', so the comparison is sound. It is tempting because off-by-one errors are common, yet 'abc123' passes via the digit test, not the length test. Changing to > would wrongly reject valid eight-character passwords.
Go deeper
Related to this question
About these practice questions
This FC0-U71 question is part of Courseiva's 988-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This FC0-U71 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the FC0-U71 exam.