function checkPrime(num){
for (let i = 2; i < num; i++){
if(num % i === 0){
}
}
}
function detectPrime(arr){
if (checkPrime){
return true;
}else{
return false;
}
}
console.log(detectPrime([15,110,7,22,25]));// true
console.log(detectPrime([15,110,77,290,20]));// false
…
i want to run a code that prints booleans(true) if any of the elements in the array contains a prime number. I’ve declared a prime number function but I want to insect it in the detect function and print the right output. how can I do this?
To display your code in here you need to wrap it in triple back ticks. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key.
I would start with your checkPrime function. What is it supposed to return? Does it return that?
Then your detectPrime function. Don’t you need start at the beginning of arr and start testing numbers to see if any of them are primes? How would you do that?
I understand how the function is supposed to work (except the print vs return I pointed out above).
I’m asking you, can you say in the middle of the loop that none of the other numbers in the array are prime? The loop body only handles one iteration at a time.
Currently, the checkPrime function doesn’t explicitly return anything, which means it always returns undefined. You need to fix this first.
In the detectPrime function you are calling checkPrime without passing in any arguments. It looks like checkPrime is supposed to be passed in a number.