Skip to content

Commit e517905

Browse files
authored
Update solution.md
1 parent a7a3b5d commit e517905

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
We can't "replace" the first character, because strings in JavaScript are immutable.
1+
Kita tidak dapat "mengganti" karakter pertama, karena string di Javascript bersifat tidak dapat berubah.
22

3-
But we can make a new string based on the existing one, with the uppercased first character:
3+
Tetapi kita dapat membuat sebuah string baru berdasarkan yang sudah ada, dengan karakter pertama yang besar:
44

55
```js
66
let newStr = str[0].toUpperCase() + str.slice(1);
77
```
88

9-
There's a small problem though. If `str` is empty, then `str[0]` is `undefined`, and as `undefined` doesn't have the `toUpperCase()` method, we'll get an error.
9+
Tetapi ada sedikit masalah. Jika `str` bernilai kosong, maka `str[0]` bernilai `undefined`, dan `undefined` tidak memiliki method `toUpperCase()`. Hal tersebut yang menyebabkan error.
1010

11-
There are two variants here:
11+
Ada dua cara di sini:
1212

13-
1. Use `str.charAt(0)`, as it always returns a string (maybe empty).
14-
2. Add a test for an empty string.
13+
1. Gunakan `str.charAt(0)`, karena method ini selalu mengembalikan string (mungkin kosong).
14+
2. Tambahkan pengecekan string kosong.
1515

16-
Here's the 2nd variant:
16+
Berikut adalah cara yang kedua:
1717

1818
```js run demo
1919
function ucFirst(str) {
@@ -24,4 +24,3 @@ function ucFirst(str) {
2424

2525
alert( ucFirst("john") ); // John
2626
```
27-

0 commit comments

Comments
 (0)