JavaScript if else and else if

Bynayakdillip

JavaScript if else and else if

Conditional Statement are used to perform different actions based on different condition

Expression
if(condition){
       block of code
   }else if(condition){
    block of code
  }else{
 	block of code
 }

shipping.html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Country Shipping</title>
</head>

<body>
    <div id="shippingInfoId" />
</body>
<script type="text/javascript" src="shipping.js">

</html>
shipping.js
var countryName = 'USA';
if (countryName == 'USA') {
    document.getElementById('shippingInfoId').innerText = countryName + '--' + '2-day Shipping';
} else if (countryName == 'Canda') {
    document.getElementById('shippingInfoId').innerText = countryName + '--' + '3-day Shipping';
} else if (countryName == 'India') {
    document.getElementById('shippingInfoId').innerText = countryName + '--' + '1-day Shipping';
}
else {
    document.getElementById('shippingInfoId').innerText = 'Other' + '--' + '5-day Shipping';
}


About the author

nayakdillip administrator

Leave a Reply