美文网首页
Chapter 1 A Quick Dip into JavaS

Chapter 1 A Quick Dip into JavaS

作者: Smnag | 来源:发表于2019-03-31 13:32 被阅读0次
    • JavaScript is a scripting language
    • JavaScript is case sensitive
    • The name of variables should not match the keywords exactly
    Variables and values
    • var winner = 2; // a numeric value
    • var name = "Duke"; // a string
    • var isEligible = false; // booleans
    • var losers; // you can also create a variable without an initial value, and assign it a value later
    How the while loop works
    var scoops = 5;
    while (scoops > 0) {
         document.write( "Another scoops!<br>");
         scoops = scoops - 1;
    }
    document.write( "Life without ice cream isn't the same");
    
    screen print while loop
    Making decisions with JavaScript
    • a test
    if (scoops < 3) {
    alert("Ice cream is running low!");
    }
    
    • multiple tests
    if (scoops >= 5) {
    alert("Eat faster, the ice cream is going to melt!");
    } else if (scoops < 3) {
    alert("Ice cream is running low!");
    }
    
    • lots of decisions
    if (scoops >= 5) {
    alert("Eat faster, the ice cream is going to melt!");
    } else if (scoops == 3) {
    alert("Ice cream is running low!");
    } else if (scoops == 2) { alert("Going once!");
    } else if (scoops == 1) { alert("Going twice!");
    } else if (scoops == 0) { alert("Gone!");
    } else {
    alert("Still lots of ice cream left, come and get it.");
    }
    
    How do I add code to my page?
    屏幕快照 2019-03-31 下午1.31.08.png

    相关文章

      网友评论

          本文标题:Chapter 1 A Quick Dip into JavaS

          本文链接:https://www.haomeiwen.com/subject/qiiybqtx.html