JSFiddle - React, Tailwind, and code Playground

by Jordan Marechal

HTML

<h4>3. Use indexOf() and substr() or substring() to divide your name into
        two strings&mdash;firstname and lastname</h4>
      <p>We're going to use some basic built-in string functions to manipulate a
        string: your name. Modify the code in the js/hw2SplitString.js file to
        output the first and last name separately into the page below.  Your code should
        work for any name entered. See the JS file for more on what input validation
   https://jsfiddle.net/jordany2017/ofwpck1L/1/#update     is expected.
      </p>
      <p><input size="30" id="fullName"> is my full name. </p>
      <button id="splitName" >Split my name!</button>
      <br>
      <span class="firstname" id="Jordan"></span> is my first name<br>
      <span class="lastname" id="Marechal"></span> is my last name<br>

JavaScript

var splitName = document.getElementById("splitName");
splitName.onclick = function(){

       var firstname = '';
              firstname.split ("");
              var res = firstname.split("");
              
              var lastname = '';
               lastname.split("");
               var res = lastname.split("");

               var fullname = document.getElementById("fullname").value;
               
              	//fullName.indexOf(‘n’); // 1
                
						/*	fullName.indexOf(‘J’); // 0
				
            // fullName.indexOf(‘ ‘); // 5
             var fullname = ‘Jordan Marechal’;
							firstname.indexOf(‘Jordan’); // 4
               var fullname = ‘Jordan Marechal’;
								firstname.indexOf(‘J’); // 1
								language.indexOf(‘n’, 6); // 3
               var fullname = ‘Jordan Marechal’;
								lastname.indexOf(‘Marechal’); // -1
                var fullName = ‘Jordan Marechal’;
								fullName.indexOf(‘n’); // 1
               fullname.slice(6);
               fullname.slice(0,8);**/
           
               
        


               /*
                *  We've gotten the fullname from the HTML form field.
                *  Your job is to use the String.slice(), String.substring() or String.substr() functions
                *  to divide your name into separate first and last name strings and assign
                *  them to the variables provided. You may
                *  need String.indexOf() as well.
                *
                *  You may not hardcode the position of where to split the string. Your code should
                *  work for anyone's first and last name. If the user enters a name without any whitespace
                *  return that as firstname and leave lastname blank.
                *
                *  If a name has more than one whitespace (as in, using one or more middle names),
                *  make the first name 'firstname' and assign the rest to 'lastname'
                *
                **/

 ...