{"id":3376,"date":"2023-02-27T20:17:57","date_gmt":"2023-02-28T01:17:57","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/?p=3376"},"modified":"2023-02-27T20:17:57","modified_gmt":"2023-02-28T01:17:57","slug":"if-else-in-javascript-6a","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/2023\/02\/27\/if-else-in-javascript-6a\/","title":{"rendered":"If\/else in JavaScript (6a)"},"content":{"rendered":"<p>We use if\/else statements when we have a conditions that we want to test. For example, the condition should come first in the \u201cif\u201d statement. If that condition is satisfied, then the code under that block executes and the rest of the statement is skipped over. However, if the condition is not met, the console will move down and execute the code in the \u201celse\u201d bracket. The basic if\/else syntax is as follows:<\/p>\n<p>If (*condition 1*){<\/p>\n<p>*code that will execute if condition 1 is met*<\/p>\n<p>} else {<\/p>\n<p>*code that will execute if condition 1 is not met*<\/p>\n<p>}<\/p>\n<p>Alternatively, you can write more than one condition by using the \u201cif else\u201d statement. There can be as many conditions as you want. The \u201cif\u201d condition statement comes first, and then the other conditions will come under \u201cif else\u201d statements, followed up by an \u201celse\u201d if none of the conditions are met. Typically, if there are many conditions to be tested, programmers will write a \u201cswitch\u201d statement, which essentially does the same thing but is just written a little differently.<\/p>\n<p>If statements do not need an \u201cif else\u201d or an \u201celse\u201d\u2014sometimes, you only want to run a program under a certain condition and no other conditions. \u201cElse\u201d statements do not take conditions or Boolean expressions as they are designed to run when no other conditions are met.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We use if\/else statements when we have a conditions that we want to test. For example, the condition should come first in the \u201cif\u201d statement. If that condition is satisfied, then the code under that block executes and the rest of the statement is skipped over. However, if the condition is not met, the console [&hellip;]<\/p>\n","protected":false},"author":29444,"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":[663943],"tags":[],"class_list":{"0":"post-3376","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-instructor","7":"entry"},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3376","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\/29444"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/comments?post=3376"}],"version-history":[{"count":1,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3376\/revisions"}],"predecessor-version":[{"id":3377,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/3376\/revisions\/3377"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/media?parent=3376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/categories?post=3376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/tags?post=3376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}