Home > Web Front-end > JS Tutorial > body text

What are the uses of if statements, multi-branch statements, and nested statements in js

云罗郡主
Release: 2018-10-22 16:50:57
forward
3428 people have browsed it

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.

timg (4).jpg

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("很抱歉,没有顺利毕业!")
}
Copy after login

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("优秀")
}
Copy after login

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("成绩不合格,无法毕业")
        }
    }
Copy after login

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!

source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template