0
5. Write a JavaScript function that accepts a string as a parameter and converts the first letter of each word of the string in
5. Write a JavaScript function that accepts a string as a parameter and converts the first letter of each word of the string in upper case. Example string : 'the quick brown fox' Expected Output : 'The Quick Brown Fox 'only(T&Q&B&F) THE UPPER
6 Respuestas
+ 3
function upper(str) {
return str.replace(/(^| )./g, x => x.toUpperCase())
}
0
5. Write a JavaScript function that accepts a string
as a parameter and converts the first letter of each word of the string in upper case.
Example string : 'the quick brown fox'
Expected Output : 'The Quick Brown Fox 'only(T&Q&B&F) THE UPPER
0
1. take in an input and store in a variable 2. do a for loop for each char 3. inside the for loop put an if which checks if its a space 4. if true then make next char uppercase
0
thank you
0
var input = "the quick brown fox"
var words = input.split(" ");
for (i = 0; i < words.length; ++i) {
words[i] = String.fromCharCode(words[i].charCodeAt(0) - 32) + words[i].substring(1);
}
alert(words.join(" "))
0
thank you for the codes