Javascript Practical 10 | Web-Programming | WebDevs I CS

The Combine Website of all Practicals till 1 to 15 will upload Soon !!!






Practical 10


Basic Addition | Javascript #1

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Javascript</title>
</head>
<body>
    <script>
        alert("The Coder Name is Zakir Hussain");
        var x = 5;
        var y = 2;
        var z = x + y;
        document.write(z);        
    </script>
</body>
</html> 

Fibbonacci Series | JavaScript #2

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fibbonacci Series</title>
</head>
<body>
    <script>
var a = 0; // The first number
var b = 1; // The second number

for (var i = 1; i <= 20; i++) {
    document.write(a + "<br>");

    var c = a + b;

    a = b;
    b = c;
}
    </script>
</body>
</html>

Prime No. #3 | Javascript

    
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Prime Number Checker</title>
        </head>
        <body>
            <h1>Prime Number Checker</h1>
        
            <script>
                function isPrime(num) {
                    if (num <= 1) return false;
                    if (num <= 3) return true;
                
                    if (num % 2 === 0 || num % 3 === 0) return false;
                
                    for (let i = 5; i * i <= num; i += 6) {
                        if (num % i === 0 || num % (i + 2) === 0) return false;
                    }
                
                    return true;
                }
                
                const userInput = prompt("Enter a number:");
                
                const number = parseInt(userInput);
                
                const resultDiv = document.createElement("div");
                if (isNaN(number)) {
                    resultDiv.textContent = "Invalid input. Please enter a valid number.";
                } else {
                    if (isPrime(number)) {
                        resultDiv.textContent = number + " is a prime number.";
                    } else {
                        resultDiv.textContent = number + " is not a prime number.";
                    }
                }
        
                document.body.appendChild(resultDiv);
            </script>
        </body>
        </html>
        
        

Post a Comment

Previous Post Next Post