This forum is now read-only. Please use our new forums! Go to forums
banner
Close banner
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
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 ()?
Answer 510ac6697390b897a80019b6
0 votes
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);
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency