JSFiddle - React, Tailwind, and code Playground

by Jordan Marechal

JavaScript

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

               var fullname = document.getElementById("Jordan Marechal").value;
    
    
    
                var fullName = ‘Jordan Marechal’;
                fullName.indexOf(‘J’); // 0
                fullName.indexOf(‘n’); // 6
                fullName.indexOf(‘ ‘); // 6

               /*
                *  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'
                *
                **/

               var firstname = 'Placeholder first name';
               var lastname = 'Placeholder last name';


               document.getElementById("Jordan").innerHTML = firstname;
               document.getElementById("Marechal").innerHTML = lastname;