{"id":4042,"date":"2023-03-02T18:34:28","date_gmt":"2023-03-02T23:34:28","guid":{"rendered":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/?p=4042"},"modified":"2023-03-02T18:35:05","modified_gmt":"2023-03-02T23:35:05","slug":"6a-conditional-statements-in-js","status":"publish","type":"post","link":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/2023\/03\/02\/6a-conditional-statements-in-js\/","title":{"rendered":"6a: Conditional Statements in JS"},"content":{"rendered":"<p><span style=\"font-weight: 400;font-size: 8pt\">Conditional statements are used in JavaScript to perform distinct actions based on a set of conditions and determines whether a code can run. If the condition is true the code can run, and if it is false it cannot run.\u00a0<\/span><span style=\"font-size: 8pt\"><i><span style=\"font-weight: 400\">if \/ else<\/span><\/i><span style=\"font-weight: 400\"> is the most common conditional statement in JS. A condition is enclosed in the parentheses after the <\/span><i><span style=\"font-weight: 400\">if<\/span><\/i><span style=\"font-weight: 400\"> statement, and the resulting output is enclosed in curly brackets. The code tests to see if the condition is true. If there are multiple conditions, they can be declared using <\/span><i><span style=\"font-weight: 400\">else if <\/span><\/i><span style=\"font-weight: 400\">(different condition). The output will run for the condition that tests true. If all conditions test false, then the output for <\/span><i><span style=\"font-weight: 400\">else<\/span><\/i><span style=\"font-weight: 400\"> {} will run.<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;font-size: 8pt\">example:<\/span><\/p>\n<p><span style=\"font-size: 8pt\"><i><span style=\"font-weight: 400\">if<\/span><\/i><span style=\"font-weight: 400\"> (condition) {<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;font-size: 8pt\">var output = \u201coutput\u201d;<\/span><\/p>\n<p><span style=\"font-size: 8pt\"><span style=\"font-weight: 400\">}<\/span> <i><span style=\"font-weight: 400\">else if <\/span><\/i><span style=\"font-weight: 400\">(different condition) {<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;font-size: 8pt\">var output = \u201coutput2\u201d;<\/span><\/p>\n<p><span style=\"font-size: 8pt\"><span style=\"font-weight: 400\">}<\/span> <i><span style=\"font-weight: 400\">else if <\/span><\/i><span style=\"font-weight: 400\">(different condition) {<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;font-size: 8pt\">var output = \u201coutput3\u201d;<\/span><\/p>\n<p><span style=\"font-size: 8pt\"><span style=\"font-weight: 400\">}<\/span> <i><span style=\"font-weight: 400\">else <\/span><\/i><span style=\"font-weight: 400\">{<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;font-size: 8pt\">var output = \u201coutput4\u201d;<\/span><\/p>\n<p><span style=\"font-weight: 400;font-size: 8pt\">}<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Conditional statements are used in JavaScript to perform distinct actions based on a set of conditions and determines whether a code can run. If the condition is true the code can run, and if it is false it cannot run.\u00a0if \/ else is the most common conditional statement in JS. A condition is enclosed in [&hellip;]<\/p>\n","protected":false},"author":29253,"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-4042","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\/4042","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\/29253"}],"replies":[{"embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/comments?post=4042"}],"version-history":[{"count":2,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/4042\/revisions"}],"predecessor-version":[{"id":4045,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/posts\/4042\/revisions\/4045"}],"wp:attachment":[{"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/media?parent=4042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/categories?post=4042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/community.mis.temple.edu\/mis2101sec730spring2023\/wp-json\/wp\/v2\/tags?post=4042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}