// Function to check if a number is prime
function isPrime(number) {
// Check for divisibility from 2 to number - 1
for (let i = 2; i < number; i++) {
if (number % i === 0) {
return false; // Not a prime number
}
}
return number > 1; // Prime if greater than 1
}
// Check if 13 is a prime number
const result = isPrime(13);
// Display the result
console.log('Is Prime:', result); // Output: Is Prime: true
code
JavaScript Prime Number Check
This JavaScript code defines a function (isPrime) to check whether a given number is prime. It then checks if the number 13 is prime and logs the result to the console. The comments provide explanations for each part of the code.
loop
Function
Prime Number