Write a function that receives a phrase by parameter return that same phrase, but with the first and last letter of each word in uppercase.
Write a function that receives a phrase by parameter return that same phrase, but with the first and last letter of each word in uppercase.
Here you have it, it returns "FIRST AND LAST LETTER OF THE CLOUD IN SHIFT":
function strWordsToCapsFirstLast(frase) {
let strin = frase.toLowerCase().split("").join("").split(" ");
for(let i = 0 ; i < strin.length ; i++){
let len = strin[i].length-1;
if (len > 0){
strin[i] = strin[i].substring(0,1).toUpperCase() +strin[i].substring(1, len) + strin[i].substr(len).toUpperCase();
}else {
strin[i] = strin[i].toUpperCase();
}
}
return strin.join(" ");
}
let specialcaps = strWordsToCapsFirstLast("primera y última letra de cada palabra en mayúscula");
alert(specialcaps);
function firstAndLastUpperCase (word) {return word.split (""). map (function (char, index) { if (index === 0 || index === word.split (""). length-1) return char.toUpperCase (); return char; }). join ("");}