nerdexam
Cisco

300-920 · Question #59

Drag and Drop Question Drag and drop the code segments to construct a script that carries out these functions: - adds a new room - adds two users, Bob, and Alice, to the room - when both the users…

The correct answer is webex.rooms.create(title: 'My First Room')); return Promise.all[[; webex.membership.create({ roomId: room.id, personEmail: '[email protected]' }); webex.membership.create({ roomId: room.id, personEmail: '[email protected]' }); webex messages.create({ markdown: "**Hi Everyone**", roomId: room.id }). The question requires correctly ordering Webex SDK API calls using JavaScript Promises to create a room, add two users concurrently, and then send a welcome message to the room once both users are added.

Messaging

Question

Drag and Drop Question Drag and drop the code segments to construct a script that carries out these functions: - adds a new room - adds two users, Bob, and Alice, to the room - when both the users have been added, sends a welcome message Answer:

Exhibit

300-920 question #59 exhibit

Answer Area

Drag items

webex messages.create({ markdown: "**Hi Everyone**", roomId: room.id })webex membership.create({ roomId: room.id, personEmail: '[email protected]' })return Promise.all[[webex rooms.create(title: 'My First Room'))webex membership.create({ roomId: room.id, personEmail: '[email protected]' })

Correct arrangement

  • webex.rooms.create(title: 'My First Room'))
  • return Promise.all[[
  • webex.membership.create({ roomId: room.id, personEmail: '[email protected]' })
  • webex.membership.create({ roomId: room.id, personEmail: '[email protected]' })
  • webex messages.create({ markdown: "Hi Everyone", roomId: room.id })

Explanation

The question requires correctly ordering Webex SDK API calls using JavaScript Promises to create a room, add two users concurrently, and then send a welcome message to the room once both users are added.

Approach. The correct approach involves sequentially structuring the asynchronous operations using JavaScript Promises.

  1. Slot 1: The first action must be to create the room. webex.rooms.create({title: 'My First Room'}) goes here. This promise resolves with a 'room' object, which is then passed to the subsequent .then(room=>{...}) block.
  2. Slot 2: Inside the then(room=>{...}) block, the requirement is to add two users and wait for both to complete before sending a message. This is achieved using Promise.all. Therefore, return Promise.all([ is placed here to initiate the concurrent execution and ensure the subsequent .then() waits for all promises within Promise.all to resolve.
  3. Slot 3 & 4: The two user membership creations are placed next, inside the conceptual Promise.all array. webex.membership.create({ roomId: room.id, personEmail: '[email protected]' }) and webex.membership.create({ roomId: room.id, personEmail: '[email protected]' }) are dragged into these slots. The room.id is available from the parent .then(room=> scope.
  4. Slot 5: The final .then(()=>{...}) block executes only after the Promise.all (and thus both user additions) has resolved. Here, the welcome message is sent: webex.messages.create({ markdown: '**Hi Everyone**', roomId: room.id }). The room.id is still accessible through closure or implicit context from the earlier room object.

Common mistakes.

  • common_mistake. Common mistakes include:
  • Incorrect order of operations: Placing membership creation or message sending before room creation, as roomId would not be available or valid.
  • Not using Promise.all: If the two webex.membership.create calls were placed sequentially without Promise.all and without explicitly waiting, the message might be sent before both users have actually been added. The prompt explicitly states 'when both the users have been added'.
  • Misplacing return Promise.all([: If Promise.all is not returned from the first .then() block, the subsequent .then() block would execute immediately without waiting for the memberships to be created, leading to the message being sent prematurely.
  • Sending message too early: Placing webex.messages.create outside the final .then() block or before the Promise.all ensures all users are added would cause the message to be sent before the condition is met.

Concept tested. Asynchronous JavaScript programming, specifically using Promises (.then()) for sequential execution and Promise.all() for concurrent execution and waiting for multiple asynchronous operations to complete. It also tests familiarity with the Webex SDK for room creation, membership management, and message sending.

Topics

#Webex API#Room Management#Member Management#Messaging

Community Discussion

No community discussion yet for this question.

Full 300-920 Practice