DRAG DROP
You are implementing a web worker by using JavaScript and HTML5. The web worker processes a
long-running loop and returns the result to a webpage.
The web worker is defined on the webpage as follows:
You have the following requirements:
Evaluate the message value in the web worker.
Process the loop based on the iterations value that is passed from the webpage.
Return a value back to the webpage from the web worker.
You need to implement the web worker.
How should you complete the relevant code? (To answer, drag the appropriate code segment to the
correct location or locations in the answer area. Use only code segments that apply.)
Answer: See the explanation.
Explanation:
Note:
* The event object for a message event supports the following additional properties:
the data property contains the message,
the origin property retrieves the scheme, hostname and port of the document that invoked the
postMessage method,
the source property refers to the window object that contains the document that invoked the
postMessage method,
the lastEventId property returns the identifier of the last message.