The content of this article is about the usage of if statements, multi-branch statements, and nested statements in js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. helped.
Classification of if statements:
1, if
2, if else
Code examples:
var score=65; var daily=70; if (score>60 &&daily>60){ alert("顺利毕业") }else{ alert("很抱歉,没有顺利毕业!") }
3. if else if else else
Code example:
/!*Multi-branch if judgment: If there is a branch that meets the conditions, subsequent branches will not be executed. *!/
var score=65; if (score<60){ alert("不及格") }else if (score>=60 && score<70){ alert("及格") }else if (score >=70 && score<80){ alert("良") }else { alert("优秀") }
4. Nested if
Code example:
var score=65; var daily=70; if (score>60 &&daily>60){ alert("顺利毕业") }else{ if (score <60 && daily<60){ alert("成绩和考勤不合格,无法毕业") }else if (daily<60){ alert("考勤不合格,无法毕业") }else{ alert("成绩不合格,无法毕业") } }
The above is the usage of if statement, multi-branch statement and nested statement in js. All the introduction, if you want to know more about JavaScript video tutorial, please pay attention to the PHP Chinese website.
The above is the detailed content of What are the uses of if statements, multi-branch statements, and nested statements in js. For more information, please follow other related articles on the PHP Chinese website!