This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Hariex
about 11 years

Assistance needed, please!

This course gave me an idea for a code I have programmed; it decides whether a given number is a prime or not. Bellow is my current code:

var primeNumber = function (x) {
    for (i = 2; i 

Answer 510ac3ea4f89f7def6001740

2 votes

Permalink

I use the return:

var primeNumber = function (x) {
    for (i = 2; i < x; i++) {
        if (x % i === 0)
            return(x + " is not a prime number.");
    }
    return(x + " is a prime number.");
};
primeNumber(15);

In your exercise you should only use the console.log ()?

points
Submitted by rodrigoext
about 11 years

Answer 510ac6697390b897a80019b6

0 votes

Permalink

Or this:

var primeNumber = function (x) {
    for (i = 2; i < x; i++) {
        if (x % i === 0){
            console.log(x + " is not a prime number.");
            return;
        }
    }
    console.log(x + " is a prime number.");
};
primeNumber(9);
points
Submitted by rodrigoext
about 11 years