0
0
Firebasecloud~10 mins

Writing data (set, update, push) 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 write data to a Firebase Realtime Database using the set method.

Firebase
firebase.database().ref('users/user1').[1]({ name: 'Alice', age: 30 });
Drag options to blanks, or click blank then click option'
Aset
Bget
Cupdate
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using push instead of set will add a new child with a unique key.
Using update will only change specified fields without replacing all data.
2fill in blank
medium

Complete the code to update only the age field of a user in Firebase Realtime Database.

Firebase
firebase.database().ref('users/user1').[1]({ age: 31 });
Drag options to blanks, or click blank then click option'
Aupdate
Bpush
Cset
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using set will overwrite all data at the reference.
Using push is for adding new child nodes, not updating existing data.
3fill in blank
hard

Fix the error in the code to add a new message to the messages list using push.

Firebase
firebase.database().ref('messages').[1]({ text: 'Hello', timestamp: Date.now() });
Drag options to blanks, or click blank then click option'
Aupdate
Bpush
Cset
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using set will overwrite the entire messages list.
Using update requires a specific child key to update.
4fill in blank
hard

Fill both blanks to update the user's email and add a new phone number using push.

Firebase
const userRef = firebase.database().ref('users/user2');
userRef.[1]({ email: 'user2@example.com' });
userRef.child('phones').[2]('123-456-7890');
Drag options to blanks, or click blank then click option'
Aupdate
Bset
Cpush
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using set for email will overwrite all user data.
Using update to add a phone number will not create a new child node.
5fill in blank
hard

Fill all three blanks to set a new post, update its title, and add a comment using push.

Firebase
const postRef = firebase.database().ref('posts/post1');
postRef.[1]({ title: 'First Post', content: 'Hello world!' });
postRef.[2]({ title: 'Updated Post Title' });
postRef.child('comments').[3]({ text: 'Nice post!' });
Drag options to blanks, or click blank then click option'
Aset
Bupdate
Cpush
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using update first without set will fail if the post does not exist.
Using set to update the title will overwrite the entire post.
Using update to add a comment will not create a new child node.