Day 82: Capital First Letter of a String of 100DaysCodingChallenge
Hello all,
#day82
Day82
Today's task was to Write a program to capitalize the first letter of each word of a given string. Words must be separated by only one
space
Example:
Sample Input: hardik kotak
Sample Output: Hardik Kotak
I have started the 100 days of coding challenge to improve my programming skills..
Code :
function capital_letter(str) { str = str.split(" "); for (var i = 0, x = str.length; i < x; i++) { str[i] = str[i][0].toUpperCase() + str[i].substr(1); } return str.join(" "); } //console.log(capital_letter("Write a JavaScript program to capitalize the first letter of each word of a given string.")); let str = prompt("Enter a String : "); console.log(capital_letter(str));
Output :
Happy Coding:)
Thank you...
Comments
Post a Comment