Prev Demo
JavaScript
>
How To Write If Statement In Javascript?
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Example for IF statement</h1> <script> function Check() { var myName = document.getElementById("txtName").value; // if block if (myName == "Sheo") { alert("Yes"); } // if else block if (myName == "Sheo") { alert("Yes"); } else { alert("No"); } // if else if else block if (myName == "Sheo") { alert("Yes"); } else if (myName == "Sheo Narayan") { alert("Yes"); } else { alert("No"); } } </script> Enter your name: <input type="text" id="txtName" /> <input type="button" id="btnSubmit" value="Check my name" onclick="Check()" /> <p><strong>Note:</strong> Enter 'Sheo' or 'Sheo Narayan' to see the positive output.</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output