Skip to content

Instantly share code, notes, and snippets.

@freyandhy
Created October 9, 2020 01:48
Show Gist options
  • Save freyandhy/83c68433b8004319f240d575c19856ea to your computer and use it in GitHub Desktop.
Save freyandhy/83c68433b8004319f240d575c19856ea to your computer and use it in GitHub Desktop.
Ini adalah script untuk nge-cek bilangan ganjil & genap
// deklrasi variabel & inputan
let number = prompt("masukkan angka ?");
// cek, jika bukan number && number >= 0 (tidak minus)
if (!isNaN(number) && number >= 0) {
// cek, jika number di modulus 2 == 0
if (number % 2 === 0) {
console.log("Genap"); // maka genap
} else {
console.log("Ganjil"); // maka ganjil
}
} else { // jika inputan salah
console.log("Input salah");
}
@Safar250501
Copy link

7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment