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>
  <meta charset="utf-8">
  <title>JS Bin</title>


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)
  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.

Solve these problems:

Python: How to check whether a file exists using Python?

C#: Loops in c#

PHP: For each

SQL: JOIN using more than 5 tables

JavaScript: Blank Slide in Javascript Slideshow