0
0
Firebasecloud~10 mins

Reading data (once and listener) in Firebase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read data once from Firebase Realtime Database.

Firebase
firebase.database().ref('users').[1](snapshot => {
  console.log(snapshot.val());
});
Drag options to blanks, or click blank then click option'
Aonce
Bon
Cget
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' instead of 'once' causes continuous listening.
Using 'get' is not a method on the reference in this context.
2fill in blank
medium

Complete the code to listen for real-time updates on the 'messages' node.

Firebase
firebase.database().ref('messages').[1]('value', snapshot => {
  console.log(snapshot.val());
});
Drag options to blanks, or click blank then click option'
Aget
Bon
Conce
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'once' reads data only once, not continuously.
Using 'get' or 'fetch' are not valid methods here.
3fill in blank
hard

Fix the error in the code to properly remove the listener.

Firebase
const ref = firebase.database().ref('tasks');
ref.on('value', snapshot => {
  console.log(snapshot.val());
});

// Remove listener
ref.[1]('value');
Drag options to blanks, or click blank then click option'
AremoveListener
Bstop
Coff
Dcancel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'removeListener' or 'stop' causes errors because they don't exist.
Not removing listeners can cause memory leaks.
4fill in blank
hard

Fill both blanks to read data once and handle errors.

Firebase
firebase.database().ref('profiles').[1]('value').then(snapshot => {
  console.log(snapshot.val());
}).[2](error => {
  console.error(error);
});
Drag options to blanks, or click blank then click option'
Aonce
Bcatch
Cthen
Don
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' instead of 'once' reads data continuously.
Using 'then' instead of 'catch' for error handling is incorrect.
5fill in blank
hard

Fill all three blanks to listen for child added events and log the new child's key and value.

Firebase
firebase.database().ref('notifications').[1]('child_added', snapshot => {
  const key = snapshot.[2];
  const value = snapshot.[3]();
  console.log(key, value);
});
Drag options to blanks, or click blank then click option'
Aon
Bkey
Cval
Donce
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'once' instead of 'on' causes only one event.
Using 'val' without parentheses causes errors.
Accessing 'key' as a method instead of a property causes errors.