Wednesday 10 August 2022

Javascript Program3 Check whether the entered string begins and ends with X or not (X is any character of your choice)

Check whether the entered string begins and ends with X or not (X is any character of your choice) 


<!DOCTYPE html>

<html>

<body>


<p>Click the button to check where if the string starts with the specified value.</p>


Enter Name: <input type="text" name="txt_name" id="name"/> <br/>

//<input type="text" name="txt_name1" id="name1" size="1" maxlength="1"/>


<button onclick="myFunction()">Try it</button>


<p id="demo"></p>


<p><strong>Note:</strong> The startsWith() method is not supported in IE 11 (and earlier versions).</p>


<script>

function myFunction() {

  var str = document.getElementById("name").value;

  //var test = document.getElementById("name1").value;

  var n = str.startsWith

  //document.getElementById("demo").innerHTML = n + n1;

  

  if(n == true) {

document.getElementById("demo").innerHTML = "Valid String";

  }

  else {

document.getElementById("demo").innerHTML = "Invalid String";

  }

}

</script>


</body>

</html>

Javascript Program2 :Read 2 numbers and perform the Arithmetic operations (+, -, *, /) on them, and show the output of the operations.

 <html>

<head>

<title>math</title>

   <script type= "text/javascript ">

  <!--

    function oper()

    {

        var ch=parseInt(prompt( "Enter your choice 1.Addition 2.Subtraction 3.Multiplication 4.Division "));

                switch(ch)

    {

        case 1:var v1=parseInt(prompt( "Enter the first value "));

                   var v2=parseInt(prompt( "Enter the second value "));

                   var v3=v1+v2;

                   document.writeln( "<br> "+ "Addition: "+v3);

                   break;

        case 2:var v4=parseInt(prompt( "Enter the first value "));

                   var v5=parseInt(prompt( "Enter the second value "));

                   var v6=v4-v5;

                   document.writeln( "<br> "+ "Subtraction: "+v6);

                   break;

        case 3:var v7=parseInt(prompt( "Enter the first value "));

                   var v8=parseInt(prompt( "Enter the second value "));

                   var v9=v7*v8;

                   document.writeln( "<br> "+ "Multiplication:  "+v9);

                   break;

        case 4:var v10=parseInt(prompt( "Enter the first value "));

                   var v11=parseInt(prompt( "Enter the second value "));

                   var v12=v10/v11;

                   document.writeln( "<br> "+ "Divison: "+v12);

                   break;

        case 5:var v13=parseInt(prompt( "Enter the first value "));

                   var v14=parseInt(prompt( "Enter the second value "));

                   var v15=v13%v14;

                   document.writeln( "<br> "+ "Modulus: "+v15);

                   break;

        default: document.writeln( "Enter choice correctly ");

    }

 

}

</script>

</head>

<body onLoad= "oper()"></body>

</html>

Javascript Program1 Check whether the number is Positive, Negative, Zero

Javascript Program1 Check whether the number is Positive, Negative, Zero 


<html>

<style>


</style> 

<body>

<h3> Positive and Negative Number Checker </h3>

<br/>Enter a Number 

<input type="text" id="num_value" name="num_value" size="5">

<br><br>

<input type="submit" onclick="check_number()" value="Check Number"/>

<br><br>


<script>

 function check_number() {

var num_value= document.getElementById("num_value").value;

if (num_value >0 ) {

document.write("Number is Positive");

}

else if(num_value < 0){

document.write("Number is Negative");

}

else {

document.write("Number is zero");

}




 }

</script>

</body>

</html>