Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to increment a Firestore field by 1.
Firebase
const increment = firebase.firestore.FieldValue.[1](1);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'incrementBy' or 'incrementValue'.
Trying to increment without using FieldValue.
✗ Incorrect
The correct method to increment a Firestore field is 'increment'.
2fill in blank
mediumComplete the code to update the 'likes' field by incrementing it by 5.
Firebase
docRef.update({ likes: firebase.firestore.FieldValue.[1](5) }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' which is not a valid method here.
Using 'increase' or 'plus' which do not exist in Firestore API.
✗ Incorrect
The 'increment' method is used to increase a numeric field by a specified value.
3fill in blank
hardFix the error in the code to correctly increment the 'score' field by 10.
Firebase
db.collection('games').doc('game1').update({ score: firebase.firestore.FieldValue.[1](10) });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' or 'increase' which are not valid Firestore methods.
Using 'update' as a method of FieldValue which is incorrect.
✗ Incorrect
The correct method to increment a numeric field in Firestore is 'increment'.
4fill in blank
hardFill both blanks to increment 'views' by 1 and 'shares' by 2 in a Firestore document update.
Firebase
docRef.update({ views: firebase.firestore.FieldValue.[1](1), shares: firebase.firestore.FieldValue.[2](2) }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different methods like 'add' or 'increase' which are invalid.
Using 'update' which is not a FieldValue method.
✗ Incorrect
Both fields should use the 'increment' method to increase their values by the specified amounts.
5fill in blank
hardFill all three blanks to increment 'likes' by 3, 'comments' by 4, and 'shares' by 5 in a Firestore update.
Firebase
docRef.update({ likes: firebase.firestore.FieldValue.[1](3), comments: firebase.firestore.FieldValue.[2](4), shares: firebase.firestore.FieldValue.[3](5) }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add', 'increase', or 'update' which are not valid FieldValue methods.
Mixing different methods for different fields.
✗ Incorrect
All three fields use the 'increment' method to increase their values by the given amounts.