0
0
Expressframework~10 mins

Broadcasting to rooms in Express - Interactive Code Practice

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

Complete the code to send a message to all clients in a specific room.

Express
io.to('[1]').emit('message', 'Hello room!');
Drag options to blanks, or click blank then click option'
Asocket
Bbroadcast
Cclient
Droom1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'socket' or 'client' instead of the room name.
Using 'broadcast' which sends to all except the sender.
2fill in blank
medium

Complete the code to join a client socket to a room named 'chatroom'.

Express
socket.[1]('chatroom');
Drag options to blanks, or click blank then click option'
Ajoin
Bto
Cemit
Dleave
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'leave' which removes the socket from a room.
Using 'emit' which sends messages but does not join rooms.
3fill in blank
hard

Fix the error in broadcasting a message to all clients except the sender.

Express
socket.[1].emit('message', 'Hello everyone!');
Drag options to blanks, or click blank then click option'
Ajoin
Bto
Cbroadcast
Demit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'to' which targets a specific room.
Using 'emit' directly which sends only to the sender.
4fill in blank
hard

Fill both blanks to broadcast a message to a specific room excluding the sender.

Express
socket.[1].to('[2]').emit('message', 'Hi room!');
Drag options to blanks, or click blank then click option'
Abroadcast
Bjoin
Croom1
Demit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'join' instead of 'broadcast' for the first blank.
Using 'emit' as a property instead of a method.
5fill in blank
hard

Fill all three blanks to create a dictionary of room names and their client counts.

Express
const counts = { [1]: await io.in('[2]').allSockets().then(sockets => sockets.size), [3]: 0 };
Drag options to blanks, or click blank then click option'
AroomA
CroomB
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing room names between keys and values.
Using non-string keys or values.