if...else if... স্টেটমেন্ট হল if…else এর একটি উন্নত রূপ যা জাভাস্ক্রিপ্টকে বিভিন্ন শর্তের মধ্যে একটি সঠিক সিদ্ধান্ত নিতে দেয়।
সিনট্যাক্স
একটি if-else-if স্টেটমেন্টের সিনট্যাক্স নিম্নরূপ −
if (expression 1){
Statement(s) to be executed if expression 1 is true
}
else if (expression2){
Statement(s) to be executed if expression 2 is true
}
else if (expression3){
Statement(s) to be executed if expression 3 is true
}
else{
Statement(s) to be executed if no expression is true
} উদাহরণ
আপনি if…else if-এর সাথে কীভাবে কাজ করবেন তা শিখতে নিচের চালানোর চেষ্টা করতে পারেন জাভাস্ক্রিপ্ট -
-এ বিবৃতিলাইভ ডেমো
<html>
<body>
<script>
var book= "maths";
if( book== "history" ){
document.write("<b>History Book</b>");
}
else if(book == "maths" ){
document.write("<b>Maths Book</b>");
}
else if(book == "economics" ){
document.write("<b>EconomicsBook</b>");
}
else{
document.write("<b>Unknown Book</b>");
}
</script>
</body>
<html>