Chapter 1 A Quick Dip into JavaScript

  • 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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,672评论 0 10
  • 我高一的时候患上了神经衰弱,一直想要描述一下那段灰暗破败的日子。但是,首先呢,不知从哪说起,其次,也特别怕被误认为...
    六月东来阅读 439评论 0 0
  • 今天是2018年10月31号,十月的最后一天。数学学得减法算式,做了口算题卡上的题。语文学的江南,还让我们写字。围...
    韩策阅读 165评论 0 0
  • 大家对优惠券应该都比较熟悉,有过网购经验的人应该都用过,优惠券也是商家促销一种常用的手段,今天来跟大家介绍下B2C...
    游社长阅读 919评论 0 16
  • 书摘 心得 最近这两天每天都在做梦,最近压力比较大,我猜一定是现实生活中的痛苦引发了这些梦。
    金黄的麦穗阅读 161评论 0 0

友情链接更多精彩内容