Use JavaScript and HTML to print first 10 even numbers - Practical [ SWPD 4311603 ]

Practical Aim: Use JavaScript and HTML to print first 10 even numbers

Use JavaScript and HTML to print first 10 even numbers

First, try at own



Code

PrintFirst10Number.html file

JavaScript and HTML to print first 10 even numbers
<!doctype html>
<html>
<head>
  <title>JavaScript to print Even Numbers within a Range!</title>
  <style>
    .wrapper{
      padding:10px;
      margin: 20px;
      background-color: blue;
      color: aliceblue;
    }
    input{
      height: 20px;
    }
   
    label{
      color: aliceblue;
      font-weight: bold;
    }
   
  </style>
   
    <script>
      function printEvenNum(){
        var totaleven = parseInt(document.getElementById("totaleven").value);
        var evenNums = "<br>Even Numbers:<br>";
        var count = 0;
 
        for(i=1; count <totaleven; i++){
          // let's divide the value by 2
          // if the reminder is zero then it's an Even number
          if(i % 2 == 0 ){
            evenNums += i + "<br>";
            count = count + 1;
          }
        }
        //print the values
        document.getElementById("result").innerHTML = evenNums;
      }
    </script>

</head>
<body>
  <div class="wrapper">
  <h3>JavaScript to print First N Even Numbers</h3>
 <label>First</label>  <input type="number" min="0" id="totaleven"  value="10"/>
 <label> Even Number</label><br>
  <br><input type="button" onclick="printEvenNum()" value="Print Even Numbers" />
  <div id="result"></div>

  </div>

</body>
</html>


Try here

<!DOCTYPE html >
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<h1> Try your code here</h1>
</body>
</html>



Output


Post a Comment

0 Comments