-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathconsole_javascript.html
More file actions
executable file
·137 lines (93 loc) · 2.91 KB
/
console_javascript.html
File metadata and controls
executable file
·137 lines (93 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html>
<!-- This was one of Scott Murray's Knight D3 course files, modified a bit. -->
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Example</title>
<style type="text/css">
body {
background-color: #ddddff;
}
</style>
</head>
<body>
<h1>Nothing here except this heading</h1>
<p> Everything of interest in this file is in the console window. Open it with Command-Opt-I on a Mac, or use the menus. Then reload and look at the console.
<script type="text/javascript">
//JavaScript code goes here,
//between the script tags.
//This is a comment, because it begins
//with two slashes, so JavaScript ignores it.
// If you want to play with these yourself, uncomment the lines you want to see
// printed to the console. Save and reload, if you already had it loaded.
//Variables
var number = 5;
var text = "bananas";
console.log(number);
console.log(text);
//console.log("I have " + number + " " + text + ".");
//Arrays
var array = [ 5, 10, 15, 20, 25 ];
console.log(array);
//console.log("The value in position 0 is " + array[0]);
// console.log("The value in position 1 is " + array[1]);
// console.log("The value in position 2 is " + array[2]);
// console.log("The value in position 3 is " + array[3]);
//console.log("The value in position 4 is " + array[4]);
//Objects
var myobject = {
"Name": "Alice",
"Age": 25,
"Title": "Graduate Student"
};
// console.log(object);
// console.log("The name is " + object.Name);
//Array of objects
var dataset = [
{
"Name": "Alice",
"Age": 25,
"Title": "Graduate Student"
},
{
"Name": "Bob",
"Age": 34,
"Title": "Associate Editor"
},
{
"Name": "Carmen",
"Age": 42,
"Title": "Senior Editor"
},
{
"Name": "Dan",
"Age": 19,
"Title": "Production Intern"
},
{
"Name": "Esmerelda",
"Age": 29,
"Title": "Freelance Reporter"
},
{
"Name": "Frank",
"Age": 51,
"Title": "Photographer"
}
];
console.log(dataset);
//console.log("The value in position 0 is " + dataset[0]);
// console.log("The value in position 1 is " + dataset[1]);
// console.log("The value in position 2 is " + dataset[2]);
// console.log("The value in position 3 is " + dataset[3]);
// console.log("The value in position 4 is " + dataset[4]);
// console.log("The value in position 5 is " + dataset[5]);
//console.log("The name in position 0 is " + dataset[0].Name);
// console.log("The name in position 1 is " + dataset[1].Name);
// console.log("The name in position 2 is " + dataset[2].Name);
// console.log("The name in position 3 is " + dataset[3].Name);
// console.log("The name in position 4 is " + dataset[4].Name);
// console.log("The name in position 5 is " + dataset[5].Name);
</script>
</body>
</html>