Practical 7: Write program and design test cases for the following Control and decision making statement. 1) For..loop 2) Switch..Case 3)Do...While 4)If..else

Program:

<html>
 <head>
  <script type="text/javascript">
   function display()
   {
    console.log("Hello");
    var n=Number(document.getElementById("num").value);
    
    if(n%2==0)
    {
     document.writeln("Number is EVEN");
    }
    else
    {
     document.writeln("Number is ODD");
    }
    
    document.writeln("<br/><br/><br/> Number 1 to "+n+" is:");
    
    for(i=1;i<=n;i++)
    {
     document.writeln(i);    
    }
    document.writeln("<br/><br/><br/> Displaying Number in Words: ");
    switch(n)
    {
     case 1: document.writeln("One");
       break;

     case 2: document.writeln("Two");
       break;
       
     case 3: document.writeln("Three");
       break;
       
     case 4: document.writeln("Four");
       break;
       
     case 5: document.writeln("Five");
       break;
     default: document.writeln(" To display number in words enter less than 5 ");
       break;
    }
   }
  </script> 
 </head>
 <body bgcolor="grad">
   Enter any Number: 
   <input type="text" id="num"/>
   <button onclick="display()"> Display </button>
 </body>
</html>



Test Cases:


Previous
Next Post »