Skip to content
Foxipa
Code Completion 8 Challenges

Complete the control-flow and declaration code

Practice branching, switch control, loop control, returns, exceptions, cleanup, and safe return syntax by completing real JavaScript code.

Intermediate ~8 min read

Challenge 1

Write the condition that checks whether score is at least 80.

javascript Your answer
if (score ) { result = "pass"; }

Press Ctrl⌘Enter to check your answer

Challenge 2

Exit this switch case after assigning the result.

javascript Your answer
case "save":
  result = "saved";
  
case "load":

Press Ctrl⌘Enter to check your answer

Challenge 3

Skip the current loop iteration when value is zero.

javascript Your answer
for (const value of values) {
  if (value === 0) 
  output.push(value);
}

Press Ctrl⌘Enter to check your answer

Challenge 4

Return the successful label from the function.

javascript Your answer
function classify(ok) {
  if (ok) 
  return "retry";
}

Press Ctrl⌘Enter to check your answer

Challenge 5

Raise an Error when the input is invalid.

javascript Your answer
if (!name) {
  
}

Press Ctrl⌘Enter to check your answer

Challenge 6

Handle the thrown error.

javascript Your answer
try {
  riskyWork();
}  {
  console.log(error.message);
}

Press Ctrl⌘Enter to check your answer

Challenge 7

Run cleanup after the try/catch path.

javascript Your answer
try {
  riskyWork();
} catch (error) {
  report(error);
}  {
  cleanup();
}

Press Ctrl⌘Enter to check your answer

Challenge 8

Keep the return expression attached to return.

javascript Your answer
function value() {
  return ;
}

Press Ctrl⌘Enter to check your answer