Skip to content

Instantly share code, notes, and snippets.

@youngjinmo
Last active November 13, 2018 07:09
Show Gist options
  • Save youngjinmo/0cfea53b15b5b52cdc1a8d7e5d173da2 to your computer and use it in GitHub Desktop.
Save youngjinmo/0cfea53b15b5b52cdc1a8d7e5d173da2 to your computer and use it in GitHub Desktop.
example for function in JavaScript
var num=0;
function isPrime(num) {
// check number type
for(var i=2; i<num; i++) {
if (num % 2 === 0) {
var numType = "even";
} else if(num % i === 0) {
numType = "odd";
} else numType = "prime";
}
// boolean for prime
if (numType==="prime") {
var prime = "Yes, ";
} else {
prime = "No, ";
}
console.log(prime + "this number " + num + " is " + numType + " number.");
}
isPrime(12);
isPrime(6);
isPrime(13);
isPrime(13568);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment