-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay5Ex2.js
22 lines (20 loc) · 827 Bytes
/
Day5Ex2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*Write a function called invertCase that expects a string as a parameter.
This function should return a new string with all the same characters as
the string that was passed in but with the cases of the alphabetic characters
switched. Uppercase characters should become lowercase and
lowercase letters should become uppercase.
Characters that are not alphabetic should not change. */
//--------------------------------------------------------------------------
function invertCase(stringarg) {
var stringarr = stringarg.split("");
var newStr = "";
stringarr.forEach(function(character) {
if (character == character.toUpperCase()) {
newStr += character.toLowerCase();
} else {
newStr += character.toUpperCase();
}
});
return newStr;
}
invertCase("aBcDeF");