-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_28.js
More file actions
24 lines (21 loc) · 1014 Bytes
/
day_28.js
File metadata and controls
24 lines (21 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// WeIrD StRiNg CaSe
// Write a function toWeirdCase that accepts a string, and returns the same string with all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased.
// The indexing just explained is zero based, so the zero - ith index is even, therefore that character should be upper cased and you need to start over for each word.
// The passed in string will only consist of alphabetical characters and spaces(' '). Spaces will only be present if there are multiple words. Words will be separated by a single space(' ').
function toWeirdCase(str) {
// Your code goes here
str = str.toLowerCase();
let strCharacters = str.split("");
let result = '';
for(let i = 0; i < strCharacters.length; i++) {
if(i%2 === 0) {
result += strCharacters[i].toUpperCase();
} else {
result += strCharacters[i];
}
}
return result;
}
console.log(
`The weird case of ${"A test case"} is ${toWeirdCase("A test case")}`
);