DEV Community

Vignesh . M
Vignesh . M

Posted on

JAVASCRIPT CL - 7

DAY -7
FIND THE DIVISOR
TASK 1
find the divisior

 let count =1;
        while(count<100){
            if (count%2==0 && count %3==0){
                console.log(count);

            }
            count++;
        }
Enter fullscreen mode Exit fullscreen mode

TASK 2
find the divisor of 10 without function

let count = 1;
        while(count<20){
            if (10%count===0) {
                console.log(count);


            }
            count++;
        }

Enter fullscreen mode Exit fullscreen mode

with function to find the divisor

findDiv(10);
        function findDiv(no) {
            console.log(`find divisor = ${no}`);
            let count = 1;
            while (count <= no ){
                if (no%count==0) {
                    console.log(count);

                }
                count++;
            }
        }//output : 1 2 5 10

Enter fullscreen mode Exit fullscreen mode

TASK 3
COUNT OF DIVISOIR COUNT

countOfDiv(10);
        function countOfDiv(no) {
            console.log(`find divisor = ${no}`);
            let count = 1;
            let i=0;
            while (count <= no ){
                if (no%count==0) {


                    i++;

                }

                count++;
            }
            console.log(i);

        } // output : 4
Enter fullscreen mode Exit fullscreen mode

TASK 4:
find the given number is primeNo or not

 countOfDiv(73); //function calling
        function countOfDiv(no) { // function
            console.log(`find divisor = ${no}`);
            let count = 1; // count value
            let i = 0; // i value
            while (count <= no) { //while
                if (no % count == 0) {
                    i++;
                }

                count++;
            }
                if (i > 2) {
                    console.log("NOT A PRIME",no);

                }else{
                    console.log("GIVEN NO IS PRIME NUMBER ",no);

                }


        } //output : GIVEN NO IS PRIME NUMBER  73
Enter fullscreen mode Exit fullscreen mode

_DO-WHILE
_

*while is called entery check
sample code for entery check

let i =5;
while(i<5){
console.log("hello");
}
Enter fullscreen mode Exit fullscreen mode

*In this condtion is false .because 5 is not lesser then 5 . so this code not run .
the condition will checked by entery level . if the condition is true the code will run
or false means not run

  • do-while is called exited check

    • do-while is called exited level check because if user need the before condition will check or atleast one time the code will run

EXAMPLE CODE FOR EXITED LEVEL CHECK

let i =5;
do{
    console.log("hello");
    i++
}
while(i<5);// output : hello

Enter fullscreen mode Exit fullscreen mode

*In this code will run before condition will check.

Top comments (0)