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!
"); 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 JavaScript)