Alternativas ao If (Unless, Provided That, As Long As, In Case)

Alternativas ao If (Unless, Provided That, As Long As, In Case) — Exercise 4

/ 10

Alternativas ao If (Unless, Provided That, As Long As, In Case) — Exercise 4

Practice English grammar topic Alternativas ao If (Unless, Provided That, As Long As, In Case) with 10 multiple-choice questions. Answer at least 70% correctly to complete the test.

Outras conjunções condicionais: unless (a menos que), provided that (desde que), as long as (contanto que), in case (caso).

B2 · Intermédio Superior TOEIC 605–780 IELTS 5,5–6,5 Orações e Condicionais
10 questions Nota mínima: 70% Test 4

How to take the test

  • Read each question carefully and select the best answer.
  • The test is not timed — you can complete it at your own pace.
  • Click Enviar Teste when finished to see your score and detailed explanations.

Entre para salvar seu resultado

Você pode fazer este teste sem entrar, mas o resultado não será salvo. Entrar para acompanhar seu progresso.

  1. 1

    You want to add an item to an array `cart` only if `item` is not null. Which short-circuiting expression is suitable?

  2. 2

    You want to submit a form only if `isValidForm` is true. Which short-circuiting expression is suitable?

  3. 3

    You are building a system that needs to handle different types of user input (e.g., keyboard events, mouse clicks, touch gestures). Instead of using `if-else if` to check the input type and call the specific handler, you define a common `IInputHandler` interface and have specific handler classes implement it. What is this an application of?

  4. 4

    You want to display a loading spinner only if `isLoading` is true. Which short-circuiting expression is suitable?

  5. 5

    Which of the following is a common use case for a `switch` statement with string values?

  6. 6

    A system needs to support various sorting algorithms (e.g., QuickSort, MergeSort, BubbleSort). The choice of algorithm depends on factors like data size and expected distribution. Which design pattern would allow you to dynamically select and apply a sorting algorithm without modifying the client code that uses it, replacing a large `if-else if` structure?

  7. 7

    To map HTTP status codes to descriptive messages (e.g., 200 to 'OK', 404 to 'Not Found'), which data structure is most efficient for replacing a large `switch` statement?

  8. 8

    In a language with optional chaining, if `user` is an object, but `user.profile` is `undefined`, what will `user?.profile?.getAvatarUrl()` evaluate to?

  9. 9

    You are refactoring a system where a complex `if-else if` structure is used to manage different stages of a document approval process (e.g., 'Draft', 'Review', 'Approved', 'Rejected'). The available actions (e.g., `submit()`, `approve()`, `reject()`) and their behavior change significantly depending on the current stage. Which design pattern is best suited to model this workflow and eliminate conditional logic based on state?

  10. 10

    A function `validateUser(user)` needs to ensure `user` is an object and has a `name` property. If not, it should return `false` immediately. How would you use guard clauses for this?