Question 31
Prashant and Nikita are creating a quiz question paper collaboratively. They are each working on different sections — and complete their tasks in parallel. Meanwhile, Mayur is enjoying a single- player game that finishes when the game loop ends.
To compare productivity:
● If Prashant and Nikita (together) finish faster than Mayur, the winner is "Team".
● If Mayur finishes faster, he wins.
● If both take the same time, Mayur wins by default.
You are simulating this scenario in the browser.Prashant and Nikita are represented using parallel Promises. Mayur is represented using a single Promise. The frontend must calculate who finishes first using asynchronous logic, and display the result.
app.js
function simulateTasks() { const prashant = new Promise(resolve => setTimeout(() =>resolve("Prashant"), 3000)); const nikita = new Promise(resolve => setTimeout(() =>resolve("Nikita"), 2000)); const mayur = new Promise(resolve => setTimeout(() =>resolve("Mayur"), 4000));
const team = Promise.all([prashant, nikita]).then(() =>"Team");
Promise.race([team, mayur]).then(winner => { console.log("Winner is:", winner); });}Based on the above data, answer the given subquestions.
If Prashant and Nikita finish together in 3 seconds (since Promise.all waits for both), and Mayur finishes in 4 seconds, who wins?
Mayur
Team
Nikita
Race condition prevents output