First Draft

First Draft of the Example Files
This commit is contained in:
RobinNixon
2020-12-10 13:21:38 +00:00
parent 77a7b57c4f
commit 0335342e00
1127 changed files with 46959 additions and 56 deletions
+6
View File
@@ -0,0 +1,6 @@
<script>
document.write("a: " + (42 > 3) + "<br>")
document.write("b: " + (91 < 4) + "<br>")
document.write("c: " + (8 == 2) + "<br>")
document.write("d: " + (4 < 17) + "<br>")
</script>
+9
View File
@@ -0,0 +1,9 @@
<script>
myname = "Peter"
myage = 24
document.write("a: " + 42 + "<br>") // Numeric literal
document.write("b: " + "Hi" + "<br>") // String literal
document.write("c: " + true + "<br>") // Constant literal
document.write("d: " + myname + "<br>") // String variable
document.write("e: " + myage + "<br>") // Numeric variable
</script>
+4
View File
@@ -0,0 +1,4 @@
<script>
days_to_new_year = 366 - day_number;
if (days_to_new_year < 30) document.write("It's nearly New Year")
</script>
+4
View File
@@ -0,0 +1,4 @@
<script>
month = "July"
if (month == "October") document.write("It's the fall")
</script>
+6
View File
@@ -0,0 +1,6 @@
<script>
a = 1000
b = "1000"
if (a == b) document.write("1")
if (a === b) document.write("2")
</script>
+7
View File
@@ -0,0 +1,7 @@
<script>
a = 7; b = 11
if (a > b) document.write("a is greater than b<br>")
if (a < b) document.write("a is less than b<br>")
if (a >= b) document.write("a is greater than or equal to b<br>")
if (a <= b) document.write("a is less than or equal to b<br>")
</script>
+6
View File
@@ -0,0 +1,6 @@
<script>
a = 1; b = 0
document.write((a && b) + "<br>")
document.write((a || b) + "<br>")
document.write(( !b ) + "<br>")
</script>
+3
View File
@@ -0,0 +1,3 @@
<script>
if (finished == 1 || getnext() == 1) done = 1
</script>
+4
View File
@@ -0,0 +1,4 @@
<script>
gn = getnext()
if (finished == 1 OR gn == 1) done = 1;
</script>
+9
View File
@@ -0,0 +1,9 @@
<script>
string = "The quick brown fox jumps over the lazy dog"
with (string)
{
document.write("The string is " + length + " characters<br>")
document.write("In upper case it's: " + toUpperCase())
}
</script>
+15
View File
@@ -0,0 +1,15 @@
<script>
onerror = errorHandler
document.writ("Welcome to this website") // Deliberate error
function errorHandler(message, url, line)
{
out = "Sorry, an error was encountered.\n\n";
out += "Error: " + message + "\n";
out += "URL: " + url + "\n";
out += "Line: " + line + "\n\n";
out += "Click OK to continue.\n\n";
alert(out);
return true;
}
</script>
+10
View File
@@ -0,0 +1,10 @@
<script>
try
{
request = new XMLHTTPRequest()
}
catch(err)
{
// Use a different method to create an XML HTTP Request object
}
</script>
+7
View File
@@ -0,0 +1,7 @@
<script>
if (page == "Home") document.write("You selected Home")
else if (page == "About") document.write("You selected About")
else if (page == "News") document.write("You selected News")
else if (page == "Login") document.write("You selected Login")
else if (page == "Links") document.write("You selected Links")
</script>
+20
View File
@@ -0,0 +1,20 @@
<script>
switch (page)
{
case "Home":
document.write("You selected Home")
break
case "About":
document.write("You selected About")
break
case "News":
document.write("You selected News")
break
case "Login":
document.write("You selected Login")
break
case "Links":
document.write("You selected Links")
break
}
</script>
+23
View File
@@ -0,0 +1,23 @@
<script>
switch (page)
{
case "Home":
document.write("You selected Home")
break
case "About":
document.write("You selected About")
break
case "News":
document.write("You selected News")
break
case "Login":
document.write("You selected Login")
break
case "Links":
document.write("You selected Links")
break
default:
document.write("Unrecognized selection")
break
}
</script>
+7
View File
@@ -0,0 +1,7 @@
<script>
document.write(
a <= 5 ?
"a is less than or equal to 5" :
"a is greater than 5"
)
</script>
+9
View File
@@ -0,0 +1,9 @@
<script>
counter=0
while (counter < 5)
{
document.write("Counter: " + counter + "<br>")
++counter
}
</script>
+8
View File
@@ -0,0 +1,8 @@
<script>
count = 1
do
{
document.write(count + " times 7 is " + count * 7 + "<br>")
} while (++count <= 7)
</script>
+6
View File
@@ -0,0 +1,6 @@
<script>
for (count = 1 ; count <= 12 ; ++count)
{
document.write(count + " times 12 is " + count * 12 + "<br>");
}
</script>
+14
View File
@@ -0,0 +1,14 @@
<script>
haystack = new Array()
haystack[17] = "Needle"
for (j = 0 ; j < 20 ; ++j)
{
if (haystack[j] == "Needle")
{
document.write("<br>- Found at location " + j)
break
}
else document.write(j + ", ")
}
</script>
+17
View File
@@ -0,0 +1,17 @@
<script>
haystack = new Array()
haystack[4] = "Needle"
haystack[11] = "Needle"
haystack[17] = "Needle"
for (j = 0 ; j < 20 ; ++j)
{
if (haystack[j] == "Needle")
{
document.write("<br>- Found at location " + j + "<br>")
continue
}
document.write(j + ", ")
}
</script>