think on your feet
US /θɪŋk ɑn jʊər fiːt/
UK /θɪŋk ɑn jʊər fiːt/

1.
to be able to think and react quickly, especially in an unexpected situation
:
•
A good salesperson needs to be able to think on their feet.
•
When the unexpected question came, she had to think on her feet to give a suitable answer.