This solution is generated by ChatGPT, correctness is not guaranteed. You might also be able to find a solution fromcommunity posts.

AI solution for JavaScript Quiz on BFE.dev
71. two-way generator

The code outputs:

undefined
100
undefined

Explanation:

  • generator.next().value calls the generator without passing any value. This means the first yield statement evaluates to undefined, and console.log outputs undefined.
  • generator.next(1).value passes 1 as the value for the first yield statement. This evaluates to 100, and console.log outputs 100.
  • generator.next(1).value tries to pass another value to the generator, but there are no more yield statements to be evaluated. This means the function simply ends and outputs undefined.