Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 5, 2016
0 parents
commit 455020c
Showing
75 changed files
with
2,456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<HTML> | ||
<BODY> | ||
<SCRIPT> | ||
document.write("I think therefore I am"); | ||
</SCRIPT> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
var trekVerb = "Make "; | ||
var trekObject; | ||
trekObject = "it so!"; | ||
var trekQuote = trekVerb + trekObject; | ||
document.write(trekQuote); | ||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
var potterSays = "\"I want to read it,\" said Harry furiously, \"as it\'s mine!\""; | ||
document.write(potterSays); | ||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
var newLine = "<BR>"; | ||
var One = "One"; | ||
var line = "line"; | ||
var at = "at"; | ||
var a = "a"; | ||
var time = "time!"; | ||
var splitLine = One + newLine + line + newLine + at + newLine + a + newLine + time; | ||
document.write(splitLine); | ||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
var Inc = 42; | ||
document.write("Starting value of " + Inc + "<BR>"); | ||
var IncPreFix = ++Inc; | ||
var IncPostFix = Inc++; | ||
document.write(" IncPreFix " + IncPreFix + "<BR>"); | ||
document.write(" IncPostFix " + IncPostFix+ "<BR>"); | ||
document.write("Ending value of " + Inc); | ||
|
||
|
||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<HTML> | ||
<BODY> | ||
<FORM> | ||
<TABLE> | ||
<TR> | ||
<TD>Enter Your Name:</TD> | ||
<TD></TD> | ||
<TD><INPUT TYPE=text NAME=userName VALUE="Harry Potter"></TD> | ||
</TR> | ||
<TR> | ||
</TR> | ||
<TR> | ||
<TD>Enter Your Age:</TD> | ||
<TD></TD> | ||
<TD><INPUT TYPE=text NAME=userAge VALUE="12"></TD> | ||
</TR> | ||
<TR> | ||
</TR> | ||
<TR> | ||
<TD></TD> | ||
<TD></TD> | ||
<TD><INPUT TYPE=button VALUE="Check Age" onClick='var status = (userAge.value >= 21) ? "an adult" : "a minor"; | ||
alert(userName.value + " is " + status + ".");'></TD> | ||
</TR> | ||
</TABLE> | ||
</FORM> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
/* Tests to see whether a lower case string is | ||
greater than, equal to, or less than | ||
the same string in upper case characters. | ||
“HOGWARTS” and “hogwarts” are the test strings. */ | ||
if ("hogwarts" > "HOGWARTS") | ||
{ | ||
// lower case wins | ||
document.write("Lower case is greater than upper case!"); | ||
} | ||
else if ("hogwarts" == "HOGWARTS") | ||
{ | ||
// cases the same | ||
document.write("They are the same!"); | ||
} | ||
else | ||
{ | ||
// upper case wins | ||
document.write("Upper case is greater than lower case!"); | ||
} | ||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
var n = 1; | ||
switch (n) { | ||
case 1: | ||
{ | ||
document.write("n equals 1"); | ||
break; | ||
} | ||
case 2: | ||
{ | ||
document.write("n equals 2"); | ||
break; | ||
} | ||
case 3: | ||
{ | ||
document.write("n equals 3"); | ||
break; | ||
} | ||
default: | ||
{ | ||
document.write("No match!"); | ||
break; | ||
} | ||
} | ||
|
||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<HTML> | ||
<HEAD> | ||
<TITLE> | ||
JavaScript "Rock, Scissors, Paper" Game | ||
</TITLE> | ||
<SCRIPT> | ||
function whoWon (iplay, uplay) { | ||
// "I" am the computer | ||
if (iplay == uplay) | ||
return "IT'S A TIE! TRY AGAIN, FRAIL HUMAN ENTITY?"; | ||
if (iplay == "rock") { | ||
if (uplay == "scissors") | ||
return "I WIN! ROCK SMASHES SCISSORS! COMPUTERS FOREVER!" | ||
else | ||
return "YOU WIN. Paper covers rock. Paltry human, how did you beat me?"; | ||
} | ||
if (iplay == "scissors") { | ||
if (uplay == "paper") | ||
return "I WIN! SCISSORS CUT PAPER! CHIPS BEAT BRAINS!" | ||
else | ||
return "YOU WIN. Rock smashes scissors. Frail human, would you like to try again?"; | ||
} | ||
if (iplay == "paper") { | ||
if (uplay == "rock") | ||
return "I WIN! PAPER COVERS ROCK! ROCK AND ROLL, BABY!" | ||
else | ||
return "YOU WIN. Scissors cut paper. Oh, vain flesh and bone entity, I'll get you next time!"; | ||
} | ||
} | ||
function shakeIt(){ | ||
var randGen = Math.random(); | ||
if (randGen <= .33) | ||
var computerPlay = "rock"; | ||
if ((randGen >.33) && (randGen <= .66)) | ||
var computerPlay = "scissors"; | ||
if (randGen > .66) | ||
var computerPlay = "paper"; | ||
if (document.gameForm.game[0].checked) | ||
var personPlay = "rock"; | ||
if (document.gameForm.game[1].checked) | ||
var personPlay = "paper"; | ||
if (document.gameForm.game[2].checked) | ||
var personPlay = "scissors"; | ||
alert ("The computer played: " + computerPlay + | ||
". You played: " + personPlay + ". " + whoWon(computerPlay,personPlay)); | ||
} | ||
</SCRIPT> | ||
</HEAD> | ||
<BODY> | ||
<H2> | ||
Play "Rock, Scissors, and Paper" the JavaScript way! | ||
</H2> | ||
<UL> | ||
<Li>Rock smashes scissors! | ||
<Li>Scissors cut paper! | ||
<Li>Paper covers rock! | ||
</UL> | ||
<FORM name="gameForm"> | ||
<P>Make a choice: | ||
<BR> | ||
<input type="radio" name="game" value="Rock" checked><STRONG>Rock</STRONG><BR> | ||
<input type="radio" name="game" value="Paper"><STRONG>Paper</STRONG><BR> | ||
<input type="radio" name="game" value="Scissors"><STRONG>Scissors</STRONG> | ||
<P> | ||
<BR> | ||
<BR> | ||
<INPUT type="button" name="play" value="Play" onClick="shakeIt();"> | ||
</FORM> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
var newString = ""; | ||
var theString = prompt("Enter a string for reversal",""); | ||
var counter = theString.length; | ||
for (counter ;counter > 0 ;counter -- ) | ||
{ | ||
newString += theString.substring(counter-1, counter); | ||
} | ||
document.write(theString + " reversed is " + newString + "!"); | ||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
var counter = 10; | ||
while (counter > 0) | ||
{ | ||
document.write (counter + "<br>"); | ||
counter--; | ||
} | ||
|
||
|
||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<HTML> | ||
<BODY> | ||
<H1> | ||
<SCRIPT> | ||
var newString = ""; | ||
var theString = prompt("Enter a string for reversal",""); | ||
var counter = theString.length; | ||
do | ||
{ | ||
newString += theString.substring(counter-1, counter); | ||
counter--; | ||
} | ||
while (counter > 0 ); | ||
document.write(theString + " reversed is " + newString + "!"); | ||
</SCRIPT> | ||
</H1> | ||
</BODY> | ||
</HTML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<HTML> | ||
<BODY> | ||
<CENTER> | ||
<SCRIPT> | ||
var width=1; | ||
for (i=0; i <= 5 ; i++) | ||
{ | ||
for (x=0; x<=4; x++) | ||
{ | ||
for (y=1; y<=width; y++) | ||
{ | ||
var Number=Math.random()*10; | ||
var Ornament=Math.round(Number); | ||
if (Ornament<=1) | ||
{ | ||
document.write("O"); | ||
} | ||
if (Ornament>=2) | ||
{ | ||
document.write(" X"); | ||
} | ||
} | ||
document.write("<BR>"); | ||
width=width+1; | ||
} | ||
width=width-2; | ||
} | ||
</SCRIPT> | ||
</CENTER> | ||
</BODY> | ||
</HTML> |
Oops, something went wrong.