Permalink
Browse files

Initial upload of 2nd edition examples

  • Loading branch information...
0 parents commit 91f15cf3d22db58469b4fa11b0967d972230ce8c Nicholas C. Zakas committed Dec 6, 2009
Showing 615 changed files with 18,642 additions and 0 deletions.
@@ -0,0 +1,18 @@
+<html>
+<head>
+ <title>Add Example 1</title>
+ <script type="text/javascript">
+
+ var result1 = 5 + 5; //two numbers
+ alert(result1); //10
+ var result2 = 5 + "5"; //a number and a string
+ alert(result2); //"55"
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,19 @@
+<html>
+<head>
+ <title>Add Example 2</title>
+ <script type="text/javascript">
+
+ var num1 = 5;
+ var num2 = 10;
+ var message = "The sum of 5 and 10 is " + num1 + num2;
+ alert(message); //"The sum of 5 and 10 is 510"
+
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,20 @@
+<html>
+<head>
+ <title>Add Example 3</title>
+ <script type="text/javascript">
+
+ var num1 = 5;
+ var num2 = 10;
+ var message = "The sum of 5 and 10 is " + (num1 + num2);
+ alert(message); //"The sum of 5 and 10 is 15"
+
+
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,28 @@
+<html>
+<head>
+ <title>Assignment Operators Example 1</title>
+ <script type="text/javascript">
+
+ var num = 5;
+ alert(num); //5
+
+ num += 5;
+ alert(num); //10
+
+ num *= 2;
+ alert(num); //20
+
+ num /= 10;
+ alert(num); //2
+
+ num -= 2;
+ alert(num); //0
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,17 @@
+<html>
+<head>
+ <title>Bitwise AND Example 1</title>
+ <script type="text/javascript">
+
+ var result = 25 & 3;
+ alert(result); //outputs 1
+
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,17 @@
+<html>
+<head>
+ <title>Bitwise NOT Example 1</title>
+ <script type="text/javascript">
+
+ var num1 = 25; //binary 00000000000000000000000000011001
+ var num2 = ~num1; //binary 11111111111111111111111111100110
+ alert(num2); //-26
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,16 @@
+<html>
+<head>
+ <title>Bitwise OR Example 1</title>
+ <script type="text/javascript">
+
+ var result = 25 | 3;
+ alert(result); //27
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,16 @@
+<html>
+<head>
+ <title>Bitwise XOR Example 1</title>
+ <script type="text/javascript">
+
+ var result = 25 ^ 3;
+ alert(result); //26
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,18 @@
+<html>
+<head>
+ <title>Boolean Example 1</title>
+ <script type="text/javascript">
+
+ var message = "Hello world!";
+ var messageAsBoolean = Boolean(message);
+
+ alert(messageAsBoolean); //true
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,19 @@
+<html>
+<head>
+ <title>Boolean Example 2</title>
+ <script type="text/javascript">
+
+ var message = "Hello world!";
+ if (message){
+ alert("Value is true");
+ }
+
+
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,23 @@
+<html>
+<head>
+ <title>Break Statement Example 1</title>
+ <script type="text/javascript">
+ var num = 0;
+
+ for (var i=1; i < 10; i++) {
+ if (i % 5 == 0) {
+ break;
+ }
+ num++;
+ }
+
+ alert(num); //4
+
+
+
+ </script>
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,27 @@
+<html>
+<head>
+ <title>Break Statement Example 2</title>
+ <script type="text/javascript">
+ var num = 0;
+
+ outermost:
+ for (var i=0; i < 10; i++) {
+ for (var j=0; j < 10; j++) {
+ if (i == 5 && j == 5) {
+ break outermost;
+ }
+ num++;
+ }
+ }
+
+ alert(num); //55
+
+
+
+
+ </script>
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,17 @@
+<html>
+<head>
+ <title>Conditional Operator Example 1</title>
+ <script type="text/javascript">
+
+ var num1 = 10;
+ var num2 = 25;
+ var num3 = (num2 > num1) ? num2 : num1;
+ alert(num3); //25
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,23 @@
+<html>
+<head>
+ <title>Continue Statement Example 1</title>
+ <script type="text/javascript">
+ var num = 0;
+
+ for (var i=1; i < 10; i++) {
+ if (i % 5 == 0) {
+ continue;
+ }
+ num++;
+ }
+
+ alert(num); //8
+
+
+
+ </script>
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,27 @@
+<html>
+<head>
+ <title>Continue Statement Example 2</title>
+ <script type="text/javascript">
+ var num = 0;
+
+ outermost:
+ for (var i=0; i < 10; i++) {
+ for (var j=0; j < 10; j++) {
+ if (i == 5 && j == 5) {
+ continue outermost;
+ }
+ num++;
+ }
+ }
+
+ alert(num); //95
+
+
+
+
+ </script>
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,20 @@
+<html>
+<head>
+ <title>Divide Example 1</title>
+ <script type="text/javascript">
+
+ alert(5 / 5); //1
+ alert(5 / NaN); //NaN
+ alert(Infinity / Infinity); //NaN
+ alert(Infinity / 2); //Infinity
+ alert(5 / 0); //NaN
+ alert(10 / true); //10
+ alert(10 / false); //NaN
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,18 @@
+<html>
+<head>
+ <title>Do While Statement Example 1</title>
+ <script type="text/javascript">
+ var i = 0;
+ do {
+ i += 2;
+ } while (i < 10);
+
+ alert(i);
+
+ </script>
+
+</head>
+<body>
+
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 91f15cf

Please sign in to comment.