"use strict" for (var a = "JavaScript is a good language", b = "", i = 0; i < a.length; i++) { b += " " != a[i] ? i && " " != a[i - 1] ? a[i] : a[i].toUpperCase() : ""; } console.log(b);