Exercise 3

 

1)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Generate a random integer</title>
</head>
<body>
    <script>
        function random(min,max){
            if(min==null && max==null){
                document.write(0+ "<br>");
            }
            else if(max==null){
                document.write(Math.floor(Math.random()*min+1)+ "<br>");
            }
            else if(min==null){
                document.write( Math.floor(Math.random()*max+1)+ "<br>");
            }
            else{
                document.write( Math.floor(Math.floor()*max-min+1)+ "<br>");
            }
        }

        console.log(random(20,1));
        console.log(random(1,10));
        console.log(random(6));
        console.log(random());
    </script>
</body>
</html>

2)
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Minimum maximum</title>
</head>
<body>
    <script>
            var minValue =Math.floor(Math.random()*(20-10)+10);
            var maxValue =Math.floor(Math.random()*(20-10)+10);
            document.write(Math.min(minValue,maxValue) + " is the minimum value" + "<br>");
            document.write(Math.max(minValue,maxValue) + " is the maximum value" + "<br>");
       
    </script>
</body>
</html>

3)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Weeknd</title>
</head>
<body>
    <script>

var is_weekend =  function(date1){
    var dt = new Date(date1);
     
    if(dt.getDay() == 6 || dt.getDay() == 0)
       {
        document.write("Weekndddd" + "<br>");
        }
    else{
        document.write("Not a weekndddd");
    }
}

console.log(is_weekend('Nov 15, 2022') );
console.log(is_weekend('Nov 16, 2022') );
console.log(is_weekend('Nov 17, 2022') );

    </script>
</body>
</html>

4)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Current date time</title>
</head>
<body>
    <script>
      function getdate(){
      var d = new Date();
      document.write("Today's Date is "+d.getDate()+"/"+d.getMonth()+"/"+d.getFullYear());
      }
      getdate();
    </script>
</body>
</html>

5)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Largest 3 numbers</title>
</head>
<body>
    <script>
        var a = prompt("Enter num1");
        var b = prompt("Enter num2");
        var c = prompt("Enter num3");

        if(a>b && a>c){
            document.write("Num1 is greatest: "+a);
        }
        else if(b>a && b>c){
             document.write("Num2 is greatest: "+b);  
        }
        else{
            document.write("Num3 is greatest: "+c);
        }
    </script>    
</body>
</html>

6)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Age calculator</title>
</head>
<body>
    <script>
       
        function calculateAge (birthDate, todayDate) {
            birthDate = new Date(birthDate);
            todayDate = new Date(todayDate);

            var years = (todayDate.getFullYear() - birthDate.getFullYear());
            document.write(years);
        }
        var age = calculateAge("10/18/2003", "01/18/2023"); //month/date/year

    </script>
</body>
</html>

Comments

Popular posts from this blog

SET(A) Q1

Exercise 2

Exercise 4