Find Prime Numbers in JavaScript Using a Real-Life Example! | Coding tutorial #shorts #javascript

preview_player
Показать описание
In this video,

we'll see how to find prime numbers using javascript? we’ll use a fun real-life example with chocolates!

Imagine having 5 chocolates. You can give all to one person or split 2 and 3, but you can’t divide it equally among two. That’s what makes 5 a prime number. Now imagine having 6 chocolates you can easily give 3 each to two people. So 6 is not a prime.

We’ll turn this concept into JavaScript logic to detect prime numbers using simple and clear code perfect for beginners and visual learners.

Learn how to write a prime coding and understand how logic connects to real-world ideas.

Don't forget to like, comment, and subscribe if this helped you understand better!To know more watch the full video & Stay tuned here for the tech insights

#javascript #coding #tech #code #errormakesclever
Рекомендации по теме
Комментарии
Автор

Time Complexity: O(root(n))
Code:
import math
class Solution:
def isPrime(self, n):
# code here
if n < 2:
return False
if n in (2, 3):
return True
if n % 2 == 0 or n % 3 == 0:
return False

for i in range(5, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True

emptytree
Автор

num = int(input("Enter a number: "))

if num <= 1:
print("It is not a prime number")
elif num == 2:
print("It is a prime number")
else:
for i in range(2, int(num ** 0.5) + 1): # optimization
if num % i == 0:
print("It is not a prime number")
break
else:
print("It is a prime number")

This is the correct code

arshath
Автор

if it's a big int, you can check for divisibility by numbers from 2 up to its square root. If any number in this range divides the integer evenly, it is not a prime number. Otherwise, it is prime.

```python

def is_prime(n):
if n < 2:
return None
if n == 2:
return True

square_root_n = int(n**0.5)

for i in range (2, quare_root_n+1):
if n%i == 0:
return False
else:
return True
```

Llllvvv
Автор

Anna scala programming language pathi small tutorial poduga anna

seenuvasan
Автор

Plz explain Armstrong and palindrome concept Anna

Exploretherealitywith-me
Автор

Visual studio access pathi solunga bro...

sofisulo
Автор

If a number is divisible by 2, 3, 5, 7 then it is a composite(non prime) number otherwise prime number except 1, 2

SathyaPrakash-ul
Автор

2 also prime number it can be divided.

MenakaSelvaMuthuKumar
Автор

Bro your example for prime number is wrong
Prime number is an number which can be divided only by one and itself
So according to your example 2 can be equally divided but it is an prime number

jeevaks
Автор

Bro naa ITI muduchu irukken fitter..
But yenakku IT filed la dha romba interested irukku seralaama basic ah yenna course panna valuable ah irukkum plz bro life matter solluga..

mohamedrasin
Автор

Which programming language are you using ?

minuanand
Автор

Yotube channel for Block chain upload pannunga bro

HariBabu-zb
Автор

Only by learning from yt and practicing one can learn the skill completely??

Exploretherealitywith-me
Автор

Bro ava ava sliding window, binary search nu poittu irukkan nee innum prime layee sollitu iruuu🤦‍♂️🤦‍♂️

vjtamil
Автор

Adhukku straight ah andha for loop laye else condition use pannalameyy
Why flag???

Toxicworld
Автор

Bro can you make a video about that the AI will replace developers and engineers

Nishwan
Автор

Plzz anyone teach this code in python😢

Dhana__d
Автор

Flag concept purla bro, need detail information

saven
Автор

n=input(int())
If n=7:
Print("it's prime")
Else:
Print("it's not prime")

Vimalkumar-pnbr
join shbcf.ru