Excellent logic!!! One thing I would add here is the missing of break function. Since it is not added, it shows non-prime number as prime number. For Example:4. Once I added, it worked properly.
let num = 2; if (num == 1) { console.log(`${num} is neither prime nor composite`); } else if (num < 1) { console.log(`${num} is not a prime number`); } else { let isPrime = true; for (let i = 2; i < num; i++) { if (num % i === 0) { isPrime = false; break; } } if (isPrime) { console.log(`${num} is a prime number`); } else { console.log(`${num} is not a prime number`); } } Updated version of code
Excellent logic!!! One thing I would add here is the missing of break function. Since it is not added, it shows non-prime number as prime number. For Example:4. Once I added, it worked properly.
is video me aapke itne km likes hain or ab to ab super se uppar hogye keep going and never give up!
Thank you
Thank you your code is very fast
Thanks alot sir❤️
If number
What about if we enter the number as 2?
if i enter 2 ?
number =2;
Let's assume, i = 2; i
I put one more else if condition for particular 2 number and it solved🥰
Bhai me bhi yahi bolne aaya tha ki 2 ka ky😅
Sir 2 number ko run karayiye nhi ho rha undefined output aa rha hai
When we enter 2 then it's give undefined why
❤
first!
11:11 5 prime number nahi hai aapne bola 😅
let num = 2;
if (num == 1) {
console.log(`${num} is neither prime nor composite`);
} else if (num < 1) {
console.log(`${num} is not a prime number`);
} else {
let isPrime = true;
for (let i = 2; i < num; i++) {
if (num % i === 0) {
isPrime = false;
break;
}
}
if (isPrime) {
console.log(`${num} is a prime number`);
} else {
console.log(`${num} is not a prime number`);
}
}
Updated version of code
2 kaise check hoga
Code is not working 😮😮
Sir 2 number ko run karayiye nhi ho rha undefined output aa rha hai