Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to subscribe a device to a topic.
Firebase
firebase.messaging().subscribeToTopic(token, [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the token instead of the topic name.
Not using quotes around the topic name.
✗ Incorrect
The subscribeToTopic method requires the topic name as a string. Here, 'news' is the topic.
2fill in blank
mediumComplete the code to send a message to a topic.
Firebase
admin.messaging().send({ topic: [1], notification: { title: 'Hello', body: 'World' } }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a device token instead of a topic name.
Omitting quotes around the topic name.
✗ Incorrect
The topic field must be the topic name string, such as 'news', to send messages to all subscribers.
3fill in blank
hardFix the error in the code to unsubscribe from a topic.
Firebase
firebase.messaging().[1](token, 'news');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subscribeToTopic instead of unsubscribeFromTopic.
Using sendToTopic which is for sending messages.
✗ Incorrect
To unsubscribe a device from a topic, use unsubscribeFromTopic method.
4fill in blank
hardFill both blanks to create a message payload for topic messaging with a data payload.
Firebase
const message = { topic: [1], data: { [2]: 'value' } }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a data key that is not a string.
Mixing topic and data keys.
✗ Incorrect
The topic is set to 'sports' and the data key is 'score' with a value.
5fill in blank
hardFill all three blanks to send a notification message with a topic and a condition.
Firebase
const message = { [1]: 'weather', notification: { [2]: 'Alert', [3]: 'Rain expected' }, condition: "'weather' in topics || 'news' in topics" }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' instead of 'topic' for the topic key.
Mixing up title and body keys.
✗ Incorrect
The message uses topic to specify the topic, and title and body for notification content.