Created
April 14, 2025 07:58
-
-
Save hendrasyp/c60a25a17de23168ca62803d25625e5f to your computer and use it in GitHub Desktop.
Javascript Time Classification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JSON response dari server | |
const jsonResponse = { | |
"Waktu": "10:00-11:00" | |
}; | |
// Fungsi untuk mengklasifikasikan jadwal | |
function classifySchedule(schedule) { | |
// Memisahkan waktu mulai dan waktu selesai dari jadwal | |
const [startTime, endTime] = schedule.split('-'); | |
// Mengubah waktu menjadi format jam (24 jam) | |
const startHour = parseInt(startTime.split(':')[0], 10); | |
const endHour = parseInt(endTime.split(':')[0], 10); | |
// Klasifikasi jadwal | |
if (startHour >= 8 && endHour <= 14) { | |
return 'pagi'; | |
} else if (startHour >= 14 && endHour <= 20) { | |
return 'siang'; | |
} else { | |
return 'tidak terdefinisi'; // Jika jadwal tidak sesuai dengan kategori pagi atau siang | |
} | |
} | |
// Mengambil jadwal dari JSON response | |
const schedule = jsonResponse.Waktu; | |
// Mengklasifikasikan jadwal | |
const scheduleCategory = classifySchedule(schedule); | |
// Menampilkan hasil klasifikasi | |
console.info(`Waktu: ${jsonResponse.Waktu} adalah ${scheduleCategory}.`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment