{"id":3808,"date":"2023-03-02T00:37:22","date_gmt":"2023-03-02T05:37:22","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/?p=3808"},"modified":"2023-03-02T00:37:22","modified_gmt":"2023-03-02T05:37:22","slug":"why-do-we-use-if-else-statements-6a","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/2023\/03\/02\/why-do-we-use-if-else-statements-6a\/","title":{"rendered":"Why do we use if\/else statements? &#8211; 6A"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3809\" src=\"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/files\/2023\/03\/IF.png\" alt=\"\" width=\"294\" height=\"171\" \/><\/p>\n<p style=\"background: whitesmoke;margin: 0in 0in .25in 0in\"><span style=\"font-family: Raleway;color: #666666\">Conditional statements are used to perform different actions based on different conditions. Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.<\/span><\/p>\n<p style=\"background: whitesmoke;margin: 0in 0in .25in 0in\"><span style=\"font-family: Raleway;color: #666666\">In JavaScript we have the following conditional statements:<\/span><\/p>\n<p style=\"background: whitesmoke;margin: 0in 0in .25in 0in\"><span style=\"font-family: Raleway;color: #666666\">Use if to specify a block of code to be executed, if a specified condition is true.<br \/>\nUse else to specify a block of code to be executed if the same condition is false.<br \/>\nUse else if to specify a new condition to test, if the first condition is false.<\/span><\/p>\n<p style=\"background: whitesmoke;margin: 0in 0in .25in 0in\"><span style=\"font-family: Raleway;color: #666666\">Use the if statement to specify a block of JavaScript code to be executed if a condition is true.<\/span><\/p>\n<p style=\"background: whitesmoke;margin: 0in 0in .25in 0in\"><span style=\"font-family: Raleway;color: #666666\">Example:<\/span><\/p>\n<p style=\"background: whitesmoke;margin: 0in 0in .25in 0in\"><span style=\"font-family: Raleway;color: #666666\">If the hour is less than 10, create a \u201cGood day\u201d greeting, otherwise \u201cGood evening\u201d:<\/span><\/p>\n<p style=\"background: whitesmoke;margin: 0in 0in .25in 0in\"><span style=\"font-family: Raleway;color: #666666\">if (hour &lt; 10) {<br \/>\ngreeting = &#8220;Good day&#8221;;<br \/>\n} else {<br \/>\ngreeting = &#8220;Good evening&#8221;;<br \/>\n}<br \/>\nThe result of the greeting will be:<\/span><\/p>\n<p style=\"background: whitesmoke;margin: 0in 0in .25in 0in\"><span style=\"font-family: Raleway;color: #666666\">Good day<\/span><\/p>\n<p style=\"background: whitesmoke\"><span style=\"font-family: Raleway;color: #666666;background: whitesmoke\"><a href=\"https:\/\/www.w3schools.com\/js\/js_if_else.asp\">https:\/\/www.w3schools.com\/js\/js_if_else.asp<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Conditional statements are used to perform different actions based on different conditions. Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. In JavaScript we have the following conditional statements: Use if to specify a block of code to [&hellip;]<\/p>\n","protected":false},"author":29429,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[10531],"tags":[],"class_list":{"0":"post-3808","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-student-post","7":"entry"},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/users\/29429"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/comments?post=3808"}],"version-history":[{"count":1,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3808\/revisions"}],"predecessor-version":[{"id":3810,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3808\/revisions\/3810"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/media?parent=3808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/categories?post=3808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/tags?post=3808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}