Help please!

Hi everyone,
can anyone help me with my code, i am having a hard time trying to make the first letter of a string a capital, and the rest lowercase… here is my code

<script type=“text/javascript”>
var input= prompt(“Please input a word.”);
var thelength= input.length;
var test=“”;
for(var i=0; i<thelength; i++){
var num1 = Math.floor(Math.random() * input.length);
test += input.substring(num1,num1+1);
}
// here is where i am having my problem, i want my output to be first character UpperCase and the rest of the output LowerCase. I only thought it has something to to with the substr method but i dunno:nono: thx!
InitChar=test.substr(0,1).toUpperCase();

</script>

You could simply use something like

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

alert(input.capitalize());

If you want all the first letters of a word to be capital you could use this

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

var input = prompt('Please input a word');

if (input && input.length > 0) {
    var temp = input.split(' '), input = [];
    
    for (var i = 0; i < temp.length; i++) {
        input[i] = temp[i].capitalize();
    }
    
    alert(input.join(' '));
}

perfect, thx! can you show me however what is wrong with the following code?

var output=test.charAt(0).toUpperCase() + test.slice(1).toLowerCase();
alert(testtest);

i am trying to avoid functions and prototype just for learnings sake. I want to use a code similar to the above with a variable. so the first part test.charAt(0).touppercase() makes the first letter uppercase… and the second part is supposed to make it lowercase? what is wrong with that code?

Are you alerting the wrong variable?