zoukankan      html  css  js  c++  java
  • [译]javascript中的条件语句

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单

    源地址在此:

    https://www.youtube.com/watch?v=PMsVM7rjupU&list=PL6n9fhu94yhUA99nOsJkKXBqokT3MBK0b

    Javascript的代码是从上到下一条条运行的.如果出于某些原因你想要打乱这个顺序,或者当某些条件满足的时候优先处理某些语句的话.这时候我们就要用到条件语句了

    Javascript有如下的条件语句

    if

    if else

    if else if else

    switch

    ternary operator - 是if..else语句的一种简写

    if的例子

    var userInput = Number(prompt("Please enter a number", ""));
    if (userInput == 1) 
    {
        alert("You number is One");
    }
    if (userInput == 2) 
    {
        alert("You number is Two");
    }
    if (userInput == 3) 
    {
        alert("Your number is Three");
    }
    if(userInput != 1 && userInput != 2 && userInput != 3)
    {
        alert("Your number is not between 1 and 3");
    }

    if-else if例子

    var userInput = Number(prompt("Please enter a number", ""));
    if (userInput == 1) 
    {
        alert("You number is One");
    }
    else if (userInput == 2) 
    {
        alert("You number is Two");
    }
    else if (userInput == 3) 
    {
        alert("Your number is Three");
    }
    else 
    {
        alert("Your number is not between 1 and 3");
    }
  • 相关阅读:
    HTML5
    带参数
    类的无参方法
    类和对象
    Java新帮派——数组
    神竜出击 合三为一!
    校园欺凌——四位学生的乱伦之战!!!
    GC常见算法
    jstat
    SpringBoot2
  • 原文地址:https://www.cnblogs.com/otakuhan/p/7664915.html
Copyright © 2011-2022 走看看