i bought a duct fan that says to connect the wires (black, white, green) into the wires in the walls. can i wire the fan to an extension cord and then plug that into the wall instead of connecting to wires in the wall?
yes, if you install what's called a pigtail, which is a short length of cord rated high enough for the fixture [#14 would be sufficient], and has a grounded male pug on the end. The bare wire end needs to be secured in the fan wire junction box with the proper cord holding connector, Use wire nuts not electrical tape, and if you have an old extension cord that is 14 gauge or larger, go ahead and cut it up. Other wise you can buy a pre-made pigtail in the electrical dept of a home center. [You are basically just putting a cord onto the duct fan.] Good luck.
NO all wire junctions must by code be made in a junction box, and it MUST be accessible. Find the nearest junction box, if the circuit isn't going to be overloaded, tie into that with 12/2 romex, run that to your fan and hook them up to the fan inside the junction box on the fan. Do it right and safe.
NO! Very unsafe. Sounds like you need an electrician.