File tree Expand file tree Collapse file tree 9 files changed +263
-0
lines changed Expand file tree Collapse file tree 9 files changed +263
-0
lines changed Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > JSON </ title >
6+ < script >
7+
8+ var fidoString = '{ "name": "Fido", "breed": "Mixed", "weight": 38 }' ;
9+ var fido = JSON . parse ( fidoString ) ;
10+ console . log ( "We have made a dog out of a string! " + fido . name ) ;
11+
12+
13+ var fido2 = {
14+ name : "Fido" ,
15+ breed : "Mixed" ,
16+ weight : 38
17+ } ;
18+ var fidoString = JSON . stringify ( fido2 ) ;
19+ console . log ( "We made a string from a dog! " + fidoString ) ;
20+
21+ </ script >
22+ </ head >
23+ < body >
24+ </ body >
25+ </ html >
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > The arguments object </ title >
6+ < script >
7+
8+ function printArgs ( ) {
9+ for ( var i = 0 ; i < arguments . length ; i ++ ) {
10+ console . log ( arguments [ i ] ) ;
11+ }
12+ }
13+
14+ printArgs ( "one" , 2 , 1 + 2 , "four" ) ;
15+
16+
17+ function emote ( kind ) {
18+ if ( kind === "silence" ) {
19+ console . log ( "Player sits in silence" ) ;
20+ } else if ( kind === "says" ) {
21+ console . log ( "Player says: '" + arguments [ 1 ] + "'" ) ;
22+ }
23+ }
24+
25+ emote ( "silence" ) ;
26+ emote ( "says" , "Stand back!" ) ;
27+
28+ </ script >
29+ </ head >
30+ < body >
31+ </ body >
32+ </ html >
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > Doing more with the DOM </ title >
6+ < script >
7+ window . onload = function ( ) {
8+
9+ //
10+ // matches the first li element with the class "song"
11+ //
12+ var li = document . querySelector ( "#playlist .song" ) ;
13+
14+ console . log ( "Matched the song " + li . innerHTML ) ;
15+
16+
17+ //
18+ // create a new element and add it to the page
19+ //
20+ var newItem = document . createElement ( "li" ) ;
21+ newItem . innerText = "Your Random Heart" ;
22+ var ul = document . getElementById ( "playlist" ) ;
23+ ul . appendChild ( newItem ) ;
24+ }
25+ </ script >
26+ </ head >
27+ < body >
28+ < ul id ="playlist ">
29+ < li class ="song "> Blue Suede Strings</ li >
30+ < li class ="song "> Great Objects on Fire</ li >
31+ < li class ="song "> I Code the Line</ li >
32+ < li class ="song "> That'll be the Data</ li >
33+ </ ul >
34+ </ body >
35+ </ html >
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > Handling events in IE8 and earlier </ title >
6+ < style >
7+ span {
8+ cursor : pointer;
9+ }
10+ </ style >
11+ < script >
12+ window . onload = function ( ) {
13+ var div = document . getElementById ( "clickme" ) ;
14+ if ( div . addEventListener ) {
15+ div . addEventListener ( "click" , handleClick , false ) ;
16+ } else if ( div . attachEvent ) {
17+ div . attachEvent ( "click" , handleClick ) ;
18+ }
19+ } ;
20+
21+ function handleClick ( e ) {
22+ var evt = e || window . event ;
23+ var target ;
24+ if ( evt . target ) {
25+ target = evt . target ;
26+ } else {
27+ target = evt . srcElement ;
28+ }
29+ alert ( "You clicked on " + target . id ) ;
30+ }
31+
32+ </ script >
33+ </ head >
34+ < body >
35+ < span id ="clickme "> Click me!</ span >
36+ </ body >
37+ </ html >
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > Exception handling </ title >
6+ < script >
7+
8+ window . onload = function ( ) {
9+ try {
10+ var message = document . getElementById ( "messge" ) ;
11+ message . innerHTML = "Here's the message!" ;
12+ } catch ( error ) {
13+ console . log ( "Error! " + error . message ) ;
14+ }
15+ } ;
16+
17+ </ script >
18+ </ head >
19+ < body >
20+ < div id ="message "> </ div >
21+ </ body >
22+ </ html >
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > Computing Fibonacci numbers recursively </ title >
6+ < script >
7+ function fibonacci ( n ) {
8+ if ( n === 0 || n === 1 ) {
9+ return 1 ;
10+ } else {
11+ return ( fibonacci ( n - 1 ) + fibonacci ( n - 2 ) ) ;
12+ }
13+ }
14+
15+ for ( var i = 0 ; i < 10 ; i ++ ) {
16+ console . log ( "The fibonnaci of " + i + " is " + fibonacci ( i ) ) ;
17+ }
18+ </ script >
19+ </ head >
20+ < body >
21+ </ body >
22+ </ html >
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > Brief intro to jQuery </ title >
6+ < style >
7+ div {
8+ margin : 20px ;
9+ padding : 50px ;
10+ background-color : lightyellow;
11+ }
12+ </ style >
13+ < script src ="http://code.jquery.com/jquery-latest.min.js "> </ script >
14+ < script >
15+
16+ $ ( function ( ) {
17+ $ ( "#specialoffer" ) . click ( function ( ) {
18+ $ ( this ) . fadeOut ( 800 , function ( ) {
19+ $ ( this ) . fadeIn ( 400 ) ;
20+ } ) ;
21+ } ) ;
22+ } ) ;
23+
24+ </ script >
25+ </ head >
26+ < body >
27+ < div id ="specialoffer "> I'm a special offer</ div >
28+ </ body >
29+ </ html >
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > Handling events in with addEventListener </ title >
6+ < style >
7+ span {
8+ cursor : pointer;
9+ }
10+ </ style >
11+ < script >
12+
13+ window . addEventListener ( "load" , init , false ) ;
14+
15+ function init ( ) {
16+ var div = document . getElementById ( "clickme" ) ;
17+ div . addEventListener ( "click" , handleClick , false ) ;
18+ }
19+ function handleClick ( e ) {
20+ var target = e . target ; ;
21+ alert ( "You clicked on " + target . id ) ;
22+ target . removeEventListener ( "click" , handleClick , false ) ;
23+ }
24+
25+ /*
26+ window.onload = function() {
27+ var div = document.getElementById("clickme");
28+ div.addEventListener("click", handleClick, false);
29+ div.addEventListener("click", handleClickAgain, false);
30+ };
31+ function handleClickAgain() {
32+ alert("Another click handler just executed!");
33+ }
34+ */
35+ </ script >
36+ </ head >
37+ < body >
38+ < span id ="clickme "> Click me!</ span >
39+ </ body >
40+ </ html >
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > Regular Expressions </ title >
6+ < script >
7+
8+ var phoneNumber = new RegExp ( / ^ \d { 3 } - ? \d { 4 } $ / ) ;
9+ var amyHome = "555-1212" ;
10+ var result = amyHome . match ( phoneNumber ) ;
11+ console . log ( result ) ;
12+
13+ var invalid = "5556-1212" ;
14+ var result2 = invalid . match ( phoneNumber ) ;
15+ console . log ( result2 ) ;
16+
17+ </ script >
18+ </ head >
19+ < body >
20+ </ body >
21+ </ html >
You can’t perform that action at this time.
0 commit comments