Append <a href> with some string and "alt" of the child image

Append <a href> with some string and "alt" of the child image

I have been trying to accomplish something.

For every a tag enclosing an images,  I am trying to append some strings along with the 'alt' attribute of the image to the end of <a> tag's href attribute based on the condition that,
 if a:contains('?') then it will appended with "&text"  
else , append with "?text"

my script goes like this,

<script>
$(document).ready(function() {
$(document).ready(function() {
$('a').each(function() {
var baoBao = $('a').children('img').attr('alt');
             
                     var noQ = '?text' + baoBao;
      
              var yesQ = '&text' + baoBao;
if('a:not(:contains("?")')
{
this.href += noQ;
}
            else {
this.href += yesQ;
}
            
        });
    
});
    });

</script>

Here is a link to the JSFiddle :  http://jsfiddle.net/Kk4Sb/1/

Presently it does not work,
when i click on the image i'm directed to the page : https://api.jquery.com/jQuery/?textundefined

Can some one please help me.