The main problem is in your proper() function. You are setting correctedName to the firstLetter and theRest variables. Those are the default variables that have not been corrected with toUpperCase() and toLowerCase().
Also as a side note, since you are using a return value in the function you don't have to set firstName and lastName to correctedName. Instead you can set firstName and lastName to proper(name). And even further optimization would have you put your prompt inside of the proper() function (getting rid of the need for the name variable outside of the function).
// <head> script
var name;
var capitalLetter;
var smallLetters;
var correctedName;
var firstName;
var lastName;
function proper(name) {
var firstLetter = name.substring(0,1);
var theRest = name.substring(1);
capitalLetter = firstLetter.toUpperCase();
smallLetters = theRest.toLowerCase();
correctedName = (capitalLetter + smallLetters);
return correctedName;
}
// <body> script
var name = prompt("Please enter your first name. And feel free to type it all wonky (lots of capital letters).", "First Name");
proper(name);
firstName = correctedName;
name = prompt("Please enter your last name. And feel free to type it all wonky (lots of capital letters).", "Last Name");
proper(name);
lastName = correctedName;
document.write("<p>Your name is " + firstName + " " + lastName + ".</p>");
Optimized version:
// <head> script
function proper(name) {
return (name.substring(0,1).toUpperCase() + name.substring(1).toLowerCase());
}
// <body> script
var firstName = proper(prompt("Please enter your first name. And feel free to type it all wonky (lots of capital letters).", "First Name"));
var lastName = proper(prompt("Please enter your last name. And feel free to type it all wonky (lots of capital letters).", "Last Name"));
document.write("<p>Your name is " + firstName + " " + lastName + ".</p>");