Hint: Use Dimensions.get('screen').width to get screen width [OK]
Common Mistakes:
Calling width as a function instead of property
Using wrong method names like getWidth
Accessing screen as a property instead of argument
3. What will be the result of this React Native code snippet?
import { Vibration } from 'react-native';
Vibration.vibrate(1000);
Choose the correct behavior.
medium
A. The device vibrates for 1 second
B. The device vibrates indefinitely until stopped
C. The device vibrates for 100 milliseconds
D. No vibration occurs because vibrate needs a pattern array
Solution
Step 1: Understand Vibration.vibrate parameter
Passing a number like 1000 to Vibration.vibrate() makes the device vibrate for that many milliseconds (1000 ms = 1 second).
Step 2: Check other options
Indefinite vibration requires a pattern with repeat, 100 ms is too short, and vibrate accepts a number directly, so no pattern array is needed.
Final Answer:
The device vibrates for 1 second -> Option A
Quick Check:
Vibration.vibrate(1000) = 1 second vibration [OK]
Hint: Number argument in vibrate() is vibration duration in ms [OK]
Common Mistakes:
Thinking vibrate needs a pattern array always
Confusing milliseconds with seconds
Assuming vibrate runs indefinitely by default
4. Identify the error in this React Native code snippet that tries to vibrate the device:
import { Vibration } from 'react-native';
Vibration.vibrate([500, 1000]);
medium
A. The vibrate method requires a second argument for repeat
B. The array pattern is correct but missing a repeat flag
C. The array should be passed as a second argument, not the first
D. The vibrate method does not accept an array as argument
Solution
Step 1: Check Vibration.vibrate pattern usage
Vibration.vibrate accepts an array pattern as first argument to define vibration and pause durations.
Step 2: Understand repeat flag necessity
To repeat the pattern, a second boolean argument true is needed. Without it, the pattern runs once, so no error but possibly unintended behavior.
Final Answer:
The array pattern is correct but missing a repeat flag -> Option B
Quick Check:
Pattern array needs repeat flag to loop [OK]
Hint: Add second argument true to repeat vibration pattern [OK]
Common Mistakes:
Thinking array is invalid argument
Forgetting second argument for repeat
Passing array as second argument instead of first
5. You want to create a React Native function that vibrates the device for 500ms, then pauses for 300ms, and repeats this pattern twice. Which code snippet correctly implements this behavior?
hard
A. Vibration.vibrate(500); Vibration.vibrate(300); Vibration.vibrate(500);
B. Vibration.vibrate([500, 300, 500, 300], true); setTimeout(() => Vibration.cancel(), 2600);
C. Vibration.vibrate([500, 300], true); setTimeout(() => Vibration.cancel(), 2600);
D. Vibration.vibrate([500, 300, 500, 300], false);
Solution
Step 1: Understand the required pattern
The pattern is vibrate 500ms, pause 300ms, repeated twice: [500, 300, 500, 300].
Step 2: Use repeat false to play exactly twice
Vibration.vibrate([500, 300, 500, 300], false) executes the sequence once without looping further.
Step 3: Eliminate other options
Using true causes indefinite looping (cancel timing imprecise); shorter pattern loops incorrectly; separate calls lack pauses.
Final Answer:
Vibration.vibrate([500, 300, 500, 300], false); -> Option D
Quick Check:
Two pattern repeats = [500, 300, 500, 300], false [OK]
Hint: Unroll pattern twice with repeat false for exact repeats [OK]
Common Mistakes:
Using repeat true without precise cancel
Using false for repeat flag
Calling vibrate multiple times instead of pattern
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.