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

9th Dec 2016, 10:58 PM
Nashwan Aziz
Nashwan Aziz - avatar
6 Respostas
+ 3
function upper(str) { return str.replace(/(^| )./g, x => x.toUpperCase()) }
5th Jan 2017, 6:39 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
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
9th Dec 2016, 10:58 PM
Nashwan Aziz
Nashwan Aziz - avatar
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
9th Dec 2016, 11:14 PM
Jonathan
Jonathan - avatar
0
thank you
9th Dec 2016, 11:26 PM
Nashwan Aziz
Nashwan Aziz - avatar
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(" "))
9th Dec 2016, 11:51 PM
Kerrash
Kerrash - avatar
0
thank you for the codes
2nd Dec 2019, 5:28 AM
LEENCE LIDONDE LIDOROS
LEENCE LIDONDE LIDOROS - avatar