Bird
0
0

What will be the output of this agent code?

medium📝 Predict Output Q5 of 15
Agentic AI - Future of AI Agents
What will be the output of this agent code?
agent.goTo('https://news.com')
const headlines = agent.extractText('.headline')
console.log(headlines.length)
APrints undefined because extractText returns nothing
BPrints the number of elements with class 'headline' on the page
CThrows an error because extractText is not a function
DPrints the text of the first headline only
Step-by-Step Solution
Solution:
  1. Step 1: Understand extractText behavior

    extractText('.headline') collects text from all elements with class 'headline' and returns an array.
  2. Step 2: Analyze console.log output

    Logging headlines.length prints how many headline elements were found.
  3. Final Answer:

    Prints the number of elements with class 'headline' on the page -> Option B
  4. Quick Check:

    extractText returns array length = number of headlines [OK]
Quick Trick: extractText returns array of texts, length counts items [OK]
Common Mistakes:
  • Assuming extractText returns single string
  • Thinking extractText is undefined
  • Confusing length with text content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes