w3resource logo


CoffeeScript exercises

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 '

Solution :

HTML Code :

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</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 ' '

alert uppercase('the quick brown fox')

Live Demo :

JS Bin on jsbin.com

Post your code through Disqus :



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number