scrimba
Note at 0:25
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:25
AboutCommentsNotes
Note at 0:25
Expand for more info
index.js
run
preview
console
/* Alternating Caps 
Write a function that takes in a string of letters
and returns a sentence in which every other letter is capitalized.

Example input: "I'm so happy it's Monday"
Example output: "I'M So hApPy iT'S MoNdAy"
*/
function altCaps(str){
const newStr = [];
const strSplit = str.split('');
console.log(strSplit)

for(let i = 0; i < strSplit.length; i++) {
if(i % 2 == 0 ) {
newStr.push(strSplit[i].toUpperCase());
} else {
newStr.push(strSplit[i].toLocaleLowerCase());
}
}
return newStr.join('');
}

console.log(altCaps("When you visit Portland you have to go to VooDoo Donuts"));
console.log(altCaps("I'm so happy it's Monday"));
Console
[
"W"
,
"h"
,
"e"
,
"n"
,
" "
,
"y"
,
"o"
,
"u"
,
" "
,
"v"
,
"i"
,
"s"
,
"i"
,
"t"
,
" "
,
"P"
,
"o"
,
"r"
,
"t"
,
"l"
,
"a"
,
"n"
,
"d"
,
" "
,
"y"
,
"o"
,
"u"
,
" "
,
"h"
,
"a"
, ...]
,
"WhEn yOu vIsIt pOrTlAnD YoU HaVe tO Go tO VoOdOo dOnUtS"
,
[
"I"
,
"'"
,
"m"
,
" "
,
"s"
,
"o"
,
" "
,
"h"
,
"a"
,
"p"
,
"p"
,
"y"
,
" "
,
"i"
,
"t"
,
"'"
,
"s"
,
" "
,
"M"
,
"o"
,
"n"
,
"d"
,
"a"
,
"y"
]
,
"I'M So hApPy iT'S MoNdAy"
,
/index.html
LIVE