CoffeeScript function: Converts the first letter of each word of a string in upper case
CoffeeScript Function : Exercise-12 with Solution
Write a CoffeeScript 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 '
HTML Code :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
<title>Converts the first letter of each word of a string in upper case</title>
</head>
<body>
</body>
</html>
CoffeeScript Code :
uppercase = (str) ->
array1 = str.split(' ')
newarray1 = []
x = 0
while x < array1.length
newarray1.push array1[x].charAt(0).toUpperCase() + array1[x].slice(1)
x++
newarray1.join ' '
console.log uppercase('the quick brown fox')
Sample Output:
"The Quick Brown Fox"
Live Demo :
See the Pen coffeescript-exercise-12 by w3resource (@w3resource) on CodePen.
Improve this sample solution and post your code through Disqus.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework