MVC

  • Home
  • HTML
    • Overview
    • Formatting
  • Java Script
    • Overview
    • Validation
  • CSS
    • Overview
  • Sql
    • Overview
    • SQL Select
    • SQL Command
    • Advance Query
    • SQL Create
    • Function
    • Function vs StoreProcedure
    • Stored Procedures
  • MVC
    • OverView
    • Evolution of MVC
    • Install VisualStudio-2015
    • Create First Application
  • LINQ
    • Introduction
  • Privacy Policy

Saturday, 22 April 2017

Conditional Statements in JavaScript

  Unknown       11:39       javascriptOverview       No comments    

Conditional Statements

In This Tutorial You want to perform different actions for different situvation.
In JavaScript we have the following conditional statements:

  • if statement .
  • if-else statement .
  • if...else if....else statement.
  • switch statement.


  • if statement - If statement if you want to execute some code only if a specified condition is true

Syntax

  if (condition)
  {
          Write if condition which is true
  }

Example
<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript">
    //If Age is grater than 18 then eligible for voting
     var age= 20;
       if(age>18) {
            document.write("Age Is Valid For Vote")
          }
 </script>
</head>
</html>


  • if...else statement -  This statement if you want to execute some code if the condition is true and another code if the condition is false

Syntax

if (condition)
  {
    Write True condition.
  }
else
 {
   Write False condition.
 }

Example
<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript">
    //If Age is grater than 18 then eligable for voting
    var age= 15;
    if(age>18) {
         document.write("Age Is Valid For Vote")
        }
    else
        document.write("Age Is Not Valid For Vote")
  </script>
</head>
</html>


  • if...else if....else statement - Use this statement if you want to select one of many blocks of code to be executed

Syntax

if (condition1)
{
   code to be executed if condition1 is true
}
else if (condition2)
{
   code to be executed if condition2 is true
}
else if (condition3)
{
   code to be executed if condition3 is true
}
else
{
   code to be executed if condition1 and condition2 and condition3 are not true
}

Example
<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript">
      var d = new Date()
      var time = d.getHours()
       if (time<10) {
            document.write("Good morning");
          }
       else if (time>10 && time)<16 br=""> {
           document.write("Good day");
         }
      else if (time>16 && time)<19 br=""> {
           document.write("Good Evening");
        }
      else if (time>19 && time)<24 br=""> {
          document.write("Good Night");
        }
     else
       {
         document.write("Hello World!");
        }
  </script>
</head>
</html>


  • switch statement - Switch statement if you want to select one of many blocks of code to be executed

Syntax

switch(n)
{
  case 1:
    execute code case 1
    break;
  case 2:
    execute code case 2
    break;
  default:
    code to be executed if n is
    different from case 1 and 2
}
This is how it works: First we have a single expression n (most often a variable), that is evaluated once. The value of the expression is then compared with the values for each case in the structure. If there is a match, the block of code associated with that case is executed. Use break to prevent the code from running into the next case automatically.

Example
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
//You will receive a different greeting based
//on what day it is. Note that Sunday=0,
//Monday=1, Tuesday=2, etc.
   var d=new Date();
   theDay=d.getDay();
   switch (theDay)
    {
        case 5:
           document.write("Day is Friday");
           break;
        case 6:
            document.write("Day is Saturday");
            break;
        case 0:
             document.write("Day is Sunday");
             break;
        default:
              document.write("I'm looking forward to this weekend!");
     }
</script>
</head>
</html>

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
Email This BlogThis! Share to X Share to Facebook
Newer Post Older Post Home

0 comments :

Post a Comment

learningmvctutorial

Popular Posts

  • Difference Between function v/s store procedure
    Definition  of Store Procedure In a database management system (DBMS), a  stored procedure  is a set of Structured Query Language (SQL...
  • Overview of HTML
    What is HTML? First developed by Tim Berners-Lee in 1990 . HTML is used to create electronic documents (called pages) that are displ...
  • Overview
      SQL (Structured Query Language)   SQL  is a language that interacts with the database on the server-side. This dynamite duo has changed ...
  • What is LINQ
    LINQ  (Language Integrated Query) is a Microsoft programming model and methodology that essentially adds formal query capabilities into Mic...
  • What is Function in Sql Server
    A function is a block of code that has a name and it has a property that it is reusable. We use function in store Procedure and queries in...
  • About Javascript
    What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting langua...
  • Create Duplicate Table of existing table in SQL Server
    In This Tutorial we create table and want to same structure and same data then We create new table with data type after that  insert in ta...
  • Operator in JavaScript
    What is an operator? JavaScript has both binary and unary operators, and one special ternary operator, the conditional operator. A binar...
  • SQL Select
    The SQL SELECT Statement The SELECT statement is used to select data from a database. SQL SELECT Syntax SELECT column_name , column_n...
  • Create First Application in MVC
    We want to create Firstly application in MVC first of how we create first application Show Steps   as below-     STEP 1 .  Start Computer ...

Blog Archive

  • ▼  2017 ( 35 )
    • ►  November ( 1 )
    • ►  October ( 2 )
    • ►  September ( 4 )
    • ►  August ( 1 )
    • ►  July ( 1 )
    • ►  May ( 3 )
    • ▼  April ( 7 )
      • Fetch Unique random Record in sql server
      • Operator in JavaScript
      • Conditional Statements in JavaScript
      • Create Duplicate Table of existing table in SQL Se...
      • Email Validation using Regex Expression in Javascript
      • About Javascript
      • Advantage and Disadvantage of LINQ
    • ►  March ( 13 )
    • ►  February ( 3 )
Powered by Blogger.

Categories

  • AdvanceQuery
  • CreateApplication
  • CreateDb
  • CssOverview
  • Evolution
  • Formatting
  • Function
  • FunctionVSSp
  • HtmlOverview
  • InstallVisualStudio
  • Introduction
  • javascriptOverview
  • JsValidation
  • Mvc-vs-Asp.Net
  • OverView
  • Select
  • SqlCommand
  • SQLOverview
  • StoredProcedures

Text Widget

Sample Text

Pages

  • Home

Copyright © MVC | Powered by Blogger
Design by Vibha Acharya