title: Uncaught ReferencEerror function is not defined, how to use typeof with an if else?
body: <p>I am trying to get the initials (upper case letters) of the name that the user enters inside the text field. I get and error that my function getInitials() is not defined. Why do I get this error? Also I want to check if the function exists with typeof.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;head&gt;
  &lt;title&gt;Second task HS&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;form name="myForm" id="eForm" action="#"&gt;
  &lt;label for="name"&gt;Name&lt;/label&gt;
      &lt;input type="text" id="name" name="fullname"/&gt;&lt;br&gt;
      &lt;input name="button" type="button" value="Pick" onclick="getInitials();"/&gt;
  
  &lt;/form&gt;
  &lt;div id="result"&gt;
  &lt;/div&gt;
  
  &lt;script type="javascript"&gt;
  
      var nameInput = document.getElementById('name').value;//I need to stringify       the input and use it!
      var arr, nameArr, first, last;
      nameArr = name.split(' ');
      first = nameArr[0][0].toUpperCase();
      last = nameArr[nameArr.length - 1][0].toUpperCase();
          if(typeof getInitials == 'function'){
          function getInitials(nameArr) {
              return {first: first, last: last};
              }
                  getInitials(nameInput);
          }else{
              alert('Check getInitials!');
          }
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>