Methods
File Location
javascript-library
└── 0-PreWork
└── 1-Fundamentals
└── 11-Objects
07-methods.js <----You will be working in this file.Making a method
let obj = {
//the given input becomes name
capitalize: function(name) {
let newName = ""; //newName is a blank string where the letters from name will be entered
for (let i = 0; i < name.length; i++) {
if (i == 0) {
newName += name[0].toUpperCase(); //the first letter of name is capitalized, then added to the string newName
} else {
newName += name[i].toLowerCase(); //each subsequent letter is made lowercase, then added the string newName
}
}
console.log(newName);
}
}Practice
Bonus challenge
Last updated