Guitar strings create musical sound through vibration. Understanding how strings work with frets to create specific vibrations (and therefore specific tones) will help you to understand why your guitar sounds the way it does, instead of like a kazoo or an accordion. The important thing to remember is that a guitar makes the sound, but you make the music.
Every musical instrument has some part of it that moves in a regular, repeated motion to produce sound (a sustained tone, or pitch). On a guitar, this part is the vibrating string. A string that you bring to a certain tension and then set in motion (by a plucking action) produces a predictable sound — for example, the note A. If you tune a string of your guitar to different tensions, you get different tones. The greater the tension of a string, the higher the pitch.
You couldn’t do very much with a guitar, however, if the only way to change pitches was to frantically adjust the tension on the strings every time you pluck a string. So guitarists resort to another way to change a string’s pitch — by shortening its effective vibrating length. They do so by fretting — pushing the string against the fretboard so that it vibrates only between the fingered fret (metal wire) and the bridge.
The fact that smaller instruments such as mandolins and violins are higher in pitch than are cellos and basses (and guitars, for that matter) is no accident. Their pitch is higher because their strings are shorter. The string tension of all these instruments may be closely related, making them feel somewhat consistent in response to the hands and fingers, but the drastic difference in string lengths is what results in the wide differences of pitch among them. This principle holds true in animals, too. A Chihuahua has a higher-pitched bark than a St. Bernard because its strings — er, vocal cords — are much smaller.
Guitars make sound by amplifying string vibrations acoustically (by passing the sound waves through a hollow chamber) or electronically (by amplifying and outputting a current through a speaker). That’s the physical process anyway. Your right-hand's motion not only helps produce the sound by setting the string in motion, but also determines the rhythm (the beat or pulse), tempo (the speed of the music), and feel (interpretation, style, spin, magic, mojo, je ne sais quoi, whatever) of those pitches.
Although guitarists produce sound by strumming or plucking the strings, how a guitar produces different sounds — and the ones that you want it to make — is up to you and how you control the pitches that those strings produce. Left-hand fretting is what changes these pitches.