-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtukarCase.js
26 lines (24 loc) · 951 Bytes
/
tukarCase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
Problem
Diberikan function tukarBesarKecil(kalimat) yang menerima satu parameter berupa string. Function akan me-return string tersebut dengan menukar karakter yang uppercase menjadi lowercase, dan sebaliknya. Spasi dan simbol diabaikan.
*/
function tukarBesarKecil(kalimat) {
var temp = '';
for (var i = 0; i < kalimat.length; i++) {
var a = kalimat[i]
if (a === a.toUpperCase()) {
temp += a.toLowerCase();
} else if (a === a.toLowerCase()) {
temp += a.toUpperCase();
} else {
temp += a; // buat karakter spasi
}
}
return temp
}
// TEST CASES
console.log(tukarBesarKecil('Hello World')); // "hELLO wORLD"
console.log(tukarBesarKecil('I aM aLAY')); // "i Am Alay"
console.log(tukarBesarKecil('My Name is Bond!!')); // "mY nAME IS bOND!!"
console.log(tukarBesarKecil('IT sHOULD bE me')); // "it Should Be ME"
console.log(tukarBesarKecil('001-A-3-5TrdYW')); // "001-a-3-5tRDyw"