improvisation
The act of making something up on the spot.
Improvisation is the act of creating or performing something without preparation, making it up as you go along. When musicians improvise, they compose music spontaneously instead of reading from sheet music. When actors improvise, they invent dialogue and actions on the spot rather than following a script.
Jazz musicians are famous for improvisation. A saxophonist might start with a familiar melody, then wander into entirely new musical territory, creating sounds and patterns that have never been played before. The other musicians listen carefully and respond with their own spontaneous ideas, building something together in real time.
Improvisation isn't limited to the arts. When your carefully planned science experiment goes wrong and you have to figure out a solution with whatever materials are available, you're improvising. When a recipe calls for an ingredient you don't have and you substitute something similar, that's improvisation too.
Good improvisation requires knowledge and skill. Jazz musicians study music theory and practice their instruments for years before they can improvise well. While some people are naturally better at thinking on their feet, improvisation is a skill anyone can develop through practice and confidence.