Index

Assignment 14 CB - Capitalize words

Have the function letterCapitalize(str) take the str parameter being passed and capitalize the first letter of each word. Words will be separated by only one space.

Enter an sentence in the input field below.

$(document).ready(function() { function letterCapitalize(str) { str = str.toString().split(' '); str = str.map(function(current, index, str) { if (current === '') return current; current = current.split(''); current[0] = current[0].toUpperCase(); return current = current.join(''); }); return str.join(' '); } $('.capitalize').click(function() { var text = $('.data input').val(); if (text === '' || !isNaN(text)) { $('.result p').html('Please enter some text in the field.'); } else { $('.result p').html('Capitalized sentence is: <span>' + letterCapitalize(text) + '</span>'); } }); });