If Else statements in JavaScript Example

InfoPath alternatives for form designing SharePoint
In this post we will discuss how to use if else statement in javascript. Also you can check my previous posts  on:
Syntax of if else statement:
if (condition) {
    statements1;
}
else if (condition)  {
    statements2;
}
else if (condition)  {
    statements3;
}
else{
    statements4;
}
Example:
Below is an example of if else statement:
<script language=”JavaScript” type=”text/javascript”>
        var age = eval(prompt(“How much you scored?”, “”));
        if (age >= 60) {
            alert(“First Division”);
        }
        else if (age > 50 && age < 60) {
            alert(“Second Division”);
        }
        else if (age >= 30 && age < 50) {
            alert(“Third Division”);
        }
        else {
            alert(“Fail”);
        }
    </script>
Here in this example it will first prompt use to enter a value and according to the condition it will alert the message. See fig below:
Once you enter the value it will show alert box according to the condition like below:

Similar SharePoint 2013 Tutorials


About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply