1.Multiples of 3 and 5
Code:
let i=1;
while(i<50){
if(i%3==0 && i%5==0){
console.log(i);
}
i++;
}
What the code is doing:
- - It Start from i = 1
- - It Will Loop until i < 50
- - Check if i is divisible by both 3 and 5
- - If yes → Then it will be printed
- - Increase i every time
Screenshot of the Program:
2.Prime Number
code:
let count=0;
let num=5;
let i=1;
while(i<=num){
if(num%i==0){
count++;
}
i++
}
if(count==2){
console.log("It is a PrimeNumber")
}else{
console.log("It not a PrimeNumber")
}
What the code is doing:
- - Start with i = 1
- - Loop until i <= num
- - Check if num is divisible by i
- - If yes → increase count
- - Increase i every time
- - After loop ends: - If count == 2 → print Prime Number - Else → print Not a Prime Number
3.count of digits
Code:
let num=12345;
let count=0;
while(num>0){
num= Math.floor(num/10);
count++;
}
console.log(count)
What the code is doing:
- - Start with num = 12345
- - Start with count = 0
- - Loop until num > 0
- - Inside the loop: - Remove the last digit of num → num = Math.floor(num / 10) - Increase count by 1
- - Repeat the loop
- - After the loop ends → print count
Screenshot of the Program:



Top comments (0)