Sharp Tutorial
if else in js

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

Java Script

  • java script home
  • introduction
  • Variable Declare & Make Comment
  • operator
  • if else
  • loop
  • Array
  • Function
  • Java Script Objects
  • Java Script DOM

JS based examples

  • two number sum and diff programs
  • Pattern program in java script
  • zumble word quiz
  • Random number guess program
  • calculator in java script
  • digital clock in java script

HTML

  • HTML Home
  • Introduction
  • Commonly used tags
  • Formatting
  • Working with class
  • Apply Css
  • Layout
  • Link / Image
  • Html Forms
  • Html Tables
  • Responsive Design

CSS

  • Introduction
  • Types of Css
  • Background and Color
  • Css Formatting
  • Css Layout
  • Css Animation
  • Css Table
  • Css Effects
  • Css Pagination
  • Css Media Query

If Else

In programming, decision making is used to specify the order in which statements are executed. In this tutorial, you will learn to write if…else statements to make decisions in your program.

The if statement verifies the given condition and decides whether a block of statements are executed or not based on the condition’s result. In JS, the if statement is classified into four types as follows …

  1. Simple if statement
  2. if – else statement
  3. Multiple if statement
  4. Nested if statement
  5. if-else-if statement (if-else ladder)

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

General syntax for if - else

  if(condition) 
{
/*statement to be executed for true condition*/
}
else
{ 
/*statement to be executed for false condition */
}

Program to check if given no. is Even or Odd?

<html>
<title>JS If Else</title>
<head>
<script>
var n=parseInt(prompt("Enter the number"))
if(n%2==0)
alert("the number is even");
else
alert("the number is odd");
</script>
</head>
<body>
</body>
</html>
[codepen_embed height="265" theme_id="default" slug_hash="dyPpqwN" default_tab="js,result" user="rajputadesh"]See the Pen dyPpqwN by rajput adesh (@rajputadesh) on CodePen.[/codepen_embed]

Multiple If

Multiple if may be used 

  1. Simple if statement
  2. if – else statement
  3. Multiple if statement
  4. Nested if statement
  5. if-else-if statement (if-else ladder

Click for Complete understanding of if else.

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial