Periksa String Menggunakan Metode Bawaan
JavaScript
xxxxxxxxxx
function checkString(str) {
if(str.startsWith('S') && str.endsWith('G')) {
console.log('The string starts with S and ends with G');
}
else if(str.startsWith('S')) {
console.log('The string starts with S but does not end with G');
}
else if(str.endsWith('G')) {
console.log('The string starts does not with S but end with G');
}
else {
console.log('The string does not start with S and does not end with G');
}
}
let string = prompt('Enter a string: ');
checkString(string);
Enter a string: String The string starts with S but does not end with G
Periksa String Menggunakan Regex
JavaScript
xxxxxxxxxx
function checkString(str) {
if( /^S/i.test(str) && /G$/i.test(str)) {
console.log('The string starts with S and ends with G');
}
else if(/^S/i.test(str)) {
console.log('The string starts with S but does not ends with G');
}
else if(/G$/i.test(str)) {
console.log('The string starts does not with S but ends with G');
}
else {
console.log('The string does not start with S and does not end with G');
}
}
for (let i = 0; i < 3; i++) {
const string = prompt('Enter a string: ');
checkString(string);
}
Enter a string: String The string starts with S and ends with G Enter a string: string The string starts with S and ends with G Enter a string: JavaScript The string does not start with S and does not end with G
Linux - Cara menginstal anc-api-tools
Linux - Cara menginstal curvedns
Linux - Cara menginstal zenmap
Python - Periksa apakah suatu Angka Positif, Negatif atau 0
C - Hitung Jumlah Digit dalam Integer
C++ - Periksa Apakah Suatu Angka Prima atau Tidak
C - Temukan Angka Terbesar Menggunakan Alokasi Memori Dinamis
C++ - Periksa Tahun Kabisat
Kotlin - Membalikkan Angka
Linux - Cara menginstal zstd
C++ - Temukan Hasil Bagi dan Sisanya
Kotlin - Menemukan Faktorial dari suatu Angka
Python - Menulis File Excel (XLSX)
Linux - Cara menginstal xbitmaps
Java - Membalikkan Angka
Kotlin - Bulatkan Angka ke n Tempat Desimal
Java - Buat Piramida dan Pola
Linux - Cara menginstal zfs-test
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month