Skip to content

Commit 226afc0

Browse files
committed
added chapter 01
1 parent fc3176f commit 226afc0

14 files changed

+280
-0
lines changed

chapter01/01-HelloWorld.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="01-HelloWorld.js"></script>
9+
<script type="text/javascript">
10+
/*alert('Hello, World!');
11+
console.log('Hello, World!');*/
12+
</script>
13+
</body>
14+
</html>

chapter01/01-HelloWorld.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function output(t) {
2+
document.write('<p>' + t + '</p>');
3+
return;
4+
}
5+
6+
alert('Hello, World!');
7+
console.log('Hello, World!');
8+
output('Hello, World!');

chapter01/02-Variables.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="02-Variables.js"></script>
9+
</body>
10+
</html>

chapter01/02-Variables.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var num = 1; //{1}
2+
num = 3; //{2}
3+
4+
var price = 1.5; //{3}
5+
var name = 'Packt'; //{4}
6+
var trueValue = true; //{5}
7+
var nullVar = null; //{6}
8+
var und; //7
9+
10+
console.log("num: "+ num);
11+
console.log("name: "+ num);
12+
console.log("trueValue: "+ num);
13+
console.log("price: "+ num);
14+
console.log("nullVar: "+ nullVar);
15+
console.log("und: "+ und);

chapter01/03-Operators.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="03-Operators.js"></script>
9+
</body>
10+
</html>

chapter01/03-Operators.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Arithmetic operators */
2+
var num = 0;
3+
4+
console.log('num value is ' + num);
5+
6+
num = num + 2;
7+
8+
console.log('New num value is ' + num);
9+
10+
num = num * 3;
11+
12+
console.log('New num value is ' + num);
13+
14+
num = num / 2;
15+
16+
console.log('New num value is ' + num);
17+
18+
num++;
19+
20+
num--;
21+
22+
console.log('New num value is ' + num);
23+
24+
console.log('num mod 2 value is ' + (num % 2));
25+
26+
27+
/* Assignment operators */
28+
num += 1;
29+
num -= 2;
30+
num *= 3;
31+
num /= 2;
32+
num %= 3;
33+
34+
console.log('New num value is ' + num);
35+
36+
/* Assignment operators */
37+
console.log('num == 1 : ' + (num == 1));
38+
console.log('num === 1 : ' + (num === 1));
39+
console.log('num != 1 : ' + (num != 1));
40+
console.log('num > 1 : ' + (num > 1));
41+
console.log('num < 1 : ' + (num < 1));
42+
console.log('num >= 1 : ' + (num >= 1));
43+
console.log('num <= 1 : ' + (num <= 1));
44+
45+
46+
/* Logical operators */
47+
console.log('true && false : ' + (true && false));
48+
console.log('true || false : ' + (true || false));
49+
console.log('!true : ' + (!true));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="04-ConditionalStatements.js"></script>
9+
</body>
10+
</html>

chapter01/04-ConditionalStatements.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Example 01 - if */
2+
var num = 1;
3+
if (num == 1) {
4+
console.log("num is equal to 1");
5+
}
6+
7+
/* Example 02 - if-else */
8+
var num = 0;
9+
if (num == 1) {
10+
console.log("num is equal to 1");
11+
} else {
12+
console.log("num is not equal to 1, the value of num is " + num);
13+
}
14+
15+
/* Example 03 - if-else-if-else... */
16+
var month = 5;
17+
if (month == 1) {
18+
console.log("January");
19+
} else if (month == 2){
20+
console.log("February");
21+
} else if (month == 3){
22+
console.log("March");
23+
} else {
24+
console.log("Month is not January, February or March");
25+
}
26+
27+
/* Example 04 - switch */
28+
var month = 5;
29+
switch(month) {
30+
case 1:
31+
console.log("January");
32+
break;
33+
case 2:
34+
console.log("February");
35+
break;
36+
case 3:
37+
console.log("March");
38+
break;
39+
default:
40+
console.log("Month is not January, February or March");
41+
}

chapter01/05-Loops.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<script type="text/javascript" src="05-Loops.js"></script>
9+
</body>
10+
</html>

chapter01/05-Loops.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
console.log('**** for example ****');
2+
3+
/* for - example */
4+
for (var i=0; i<10; i++) {
5+
console.log(i);
6+
}
7+
8+
console.log('**** while example ****');
9+
/* while - example */
10+
var i = 0;
11+
while(i<10)
12+
{
13+
console.log(i);
14+
i++;
15+
}
16+
17+
console.log('**** do-while example ****');
18+
/* do-while - example */
19+
var i = 0;
20+
do {
21+
console.log(i);
22+
i++;
23+
} while (i<10)

0 commit comments

Comments
 (0)