Thinking about this little bit more, if the iMac is new enough, it might be possible to install a later version of the OS without having to make a bootable installer. Some of these iMacs that can run Yosemite can also run High Sierra. It might be worth trying this before making the installer.
How to download macOS - Apple Support
Try the High Sierra download:
If that works, you can go directly to the App Store and get High Sierra:
If this does not work, then here's the installer for El Capitan instructions:
1. Erase (Mac OS Extended (Journaled)/GUID partition) a 16 GB USB stick with the name MyVolume.
2. Download the El Capitan full installer from the link.
3. Double-click the downloaded InstallMacOSX.dmg in Downloads to mount the installer as Install OS X on the Desktop
4. Start Terminal and enter (copy and paste) the following as one command and Press Enter:
rm -rf /tmp/El\ Capitan
pkgutil --expand /Volumes/Install\ OS\ X/InstallMacOSX.pkg /tmp/El\ Capitan
diskutil eject Install\ OS\ X
cd /tmp/El\ Capitan
hdiutil attach InstallMacOSX.pkg/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/esd
sudo asr restore -source /Volumes/esd/BaseSystem.dmg -target /Volumes/MyVolume -noprompt -noverify -erase
5. When it completes and returns to command prompt, enter (copy and paste) the following as one command and Press Enter:
diskutil rename OS\ X\ Base\ System Install\ El\ Capitan
rm /Volumes/Install\ El\ Capitan/System/Installation/Packages
cp -rp /Volumes/esd/Packages /Volumes/Install\ El\ Capitan/System/Installation
cp -rp /Volumes/esd/BaseSystem.chunklist /Volumes/Install\ El\ Capitan/
cp -rp /Volumes/esd/BaseSystem.dmg /Volumes/Install\ El\ Capitan/
hdiutil detach /Volumes/esd
sudo bless --folder /Volumes/Install\ El\ Capitan/System/Library/CoreServices --label Install\ El\ Capitan
cp /Volumes/Install\ El\ Capitan/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/InstallAssistant.icns /Volumes/Install\ El\ Capitan/.VolumeIcon.icns
cd "$HOME"
rm -r /tmp/El\ Capitan
diskutil eject Install\ El\ Capitan
20 minutes later you will have the El Capitan USB boot installer. Boot your friend's Mac from it by inserting the USB stick into the Mac and pressing/holding Option key at power-on. Select the orange Install OS X icon at the gray efi boot screen using the mouse and press Enter. It will boot (slowly) from the USB stick and take you to a recovery screen where you can choose to reinstall El Capitan to the internal HDD, use Disk Utility, and more.
It's probably worth getting the Mac up and running first and then seeing what model it is and how far it can be upgraded. Post back if you have any issues with any of this.
It''s also good practice to run Disk Utility on the Disk and the volume before installing the new OS. You can do this from the internal Recovery HD. (Disk Utility repairs the complex software on the disk and should fix any corruption that might be present.)
Good Luck