mediumMultiple ChoiceObjective-mapped
FC0-U71 Practice Question: A programmer is writing an if-else statement to…
A programmer is writing an if-else statement to check if a user is an admin. The code should set a variable 'accessLevel' to 'full' if admin, else 'restricted'. Which code snippet accomplishes this?
⚠ Common exam trap
CompTIA often tests the confusion between the assignment operator (=) and the equality operator (==), as well as the tendency to misread the logic and swap the true/false branches.
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
✓
if (isAdmin == true) { accessLevel = 'full'; } else { accessLevel = 'restricted'; }
Ly uses the equality operator (==) to compare isAdmin to the boolean value true. If the condition evaluates to true, accessLevel is set to 'full'; otherwise, it is set to 'restricted'. This matches the requirement exactly.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
if (isAdmin == true) { accessLevel = 'full'; } else { accessLevel = 'restricted'; }
Why this is correct
Correctly assigns full if admin, restricted otherwise.
- ✗
if (isAdmin == false) { accessLevel = 'full'; } else { accessLevel = 'restricted'; }
Why it's wrong here
This gives full access only when not admin.
- ✗
if (isAdmin = true) { accessLevel = 'full'; } else { accessLevel = 'restricted'; }
Why it's wrong here
= is assignment, not comparison; this assigns true to isAdmin and always enters if block.
- ✗
if (isAdmin == true) { accessLevel = 'restricted'; } else { accessLevel = 'full'; }
Why it's wrong here
The assignments are reversed; admin gets restricted.
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.