بدائل If (مثل Unless, Provided That, As Long As, In Case)

بدائل If (مثل Unless, Provided That, As Long As, In Case) — Exercise 4

/ 10

بدائل If (مثل Unless, Provided That, As Long As, In Case) — Exercise 4

Practice English grammar topic بدائل If (مثل Unless, Provided That, As Long As, In Case) with 10 multiple-choice questions. Answer at least 70% correctly to complete the test.

أدوات شرط أخرى: unless (إذا لم)، provided that، as long as (فقط إذا)، in case (كإجراء احترازي).

B2 · فوق المتوسط TOEIC 605–780 IELTS 5.5–6.5 الجمل الشرطية والعبارات
10 questions درجة النجاح: 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 تسليم الاختبار when finished to see your score and detailed explanations.

سجّل دخولك لحفظ نتيجتك

يمكنك أداء هذا الاختبار دون تسجيل الدخول، لكن لن يتم حفظ نتيجتك. تسجيل الدخول لمتابعة تقدمك.

  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?

← العودة إلى الموضوع