switch evaluates its expression once and finds the first case that matches strictly. break prevents fall-through into the next case, while default handles remaining values.
Correct example✓
const role = 'editor';
switch (role) {
case 'admin':
console.log('Administrare');
break;
case 'editor':
console.log('Editare');
break;
default:
console.log('Vizualizare');
}
The editor value activates the second case and produces one message.
Common mistake!
if (role === 'editor') { console.log('Editare'); }
The result may be correct, but this exercise checks the switch structure, its cases and explicit stopping.
STEP 2 · APPLY
Your exercise
For role = “editor”, print “Editare” using switch, two cases, break and default.
STEP 3 · RUN
Write and run the code
script.jsJAVASCRIPT
Isolated consoleisolated
Preparing the runtime…
Run the code to see the result.
The draft stays only in this browser.Isolated QuickJS · no DOM, session or network
STEP 4 · CHECK
What needs to pass
0%not checked
○role is declared with const.
○switch checks role and includes admin, editor and default.
○The output is exactly Editare.
Explain the solution logic+
switch compares role with each case; break ends the editor case before default.
ANALYSIS REQUEST
Tell me briefly what you want to improve.
The initial discussion is without obligation. You receive an honest recommendation, suitable stages and the factors that affect price.
scheduleabout 2 minutestask_altno obligation
mark_email_readAfter sending, you receive an email confirmation and we continue through your chosen channel.
YOUR CONTROL
Cookie preferences
Necessary cookiesSave your preference and protect the form.
Anonymous analyticsHelps us understand which pages are useful, only after consent.