Alternatives to If (Unless, Provided That, As Long As, In Case)

Alternatives to If (Unless, Provided That, As Long As, In Case) — Bài Tập 3

/ 10

Alternatives to If (Unless, Provided That, As Long As, In Case) — Bài Tập 3

Luyện tập ngữ pháp tiếng Anh chủ đề Alternatives to If (Unless, Provided That, As Long As, In Case) qua 10 câu hỏi trắc nghiệm. Trả lời đúng ít nhất 70% để hoàn thành bài.

Other conditional conjunctions: unless (if not), provided that, as long as (only if), in case (as a precaution).

B2 · Upper Intermediate TOEIC 605–780 IELTS 5.5–6.5 Clauses & Conditionals
10 câu hỏi Điểm qua: 70% Bài 3

Hướng dẫn làm bài

  • Đọc kỹ từng câu hỏi và chọn đáp án đúng nhất.
  • Bài thi không giới hạn thời gian — bạn có thể làm theo tốc độ của mình.
  • Nhấn Nộp bài khi đã hoàn thành để xem kết quả và giải thích chi tiết.

Login to save your result

You can take this test without logging in, but your result won't be saved. Login to track your progress.

  1. 1

    Which operator is commonly used to provide a default value if a variable is null or undefined?

  2. 2

    What is the value of `result` in `const result = (temperature > 25) ? 'Hot' : 'Cool';` if `temperature` is 20?

  3. 3

    What is the value of `greeting` in `const greeting = (hour < 12) ? 'Good Morning' : 'Good Afternoon';` if `hour` is 14?

  4. 4

    Instead of using `if-else if` to check user roles and grant permissions, a developer stores permissions in a configuration object where keys are roles and values are permission lists. What is this approach an example of?

  5. 5

    In a language supporting null coalescing (e.g., `??` in JavaScript/C#), how would you assign a default value to `config.port` if `config` or `config.port` might be null/undefined?

  6. 6

    A system needs to manage different network connection states (e.g., `Disconnected`, `Connecting`, `Connected`, `Error`). The available actions (e.g., `connect()`, `disconnect()`, `sendData()`) and their behavior change significantly depending on the current state. Which design pattern is best suited to model this behavior and eliminate conditional logic based on state?

  7. 7

    In a switch statement, what happens if no `case` matches the expression and there is no `default` case?

  8. 8

    You have a system that processes different types of orders (e.g., 'OnlineOrder', 'PhoneOrder', 'RetailOrder'). Each order type has a unique way of calculating its total. Instead of using `if-else if` to check the order type and call the specific calculation logic, you define a common `calculateTotal()` method in a base `Order` class, and each specific order type overrides it. This is an example of:

  9. 9

    You have a request that needs to pass through a series of processing steps (e.g., authentication, logging, validation, authorization). Each step can decide whether to handle the request or pass it to the next handler. Which design pattern is ideal for replacing a long `if-else if` or `switch` statement that checks which handler to invoke?

  10. 10

    Which control flow statement is best suited for handling multiple possible values of a single variable or expression?