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
+12
View File
@@ -0,0 +1,12 @@
<script>
displayItems("Dog", "Cat", "Pony", "Hamster", "Tortoise")
function displayItems(v1, v2, v3, v4, v5)
{
document.write(v1 + "<br>")
document.write(v2 + "<br>")
document.write(v3 + "<br>")
document.write(v4 + "<br>")
document.write(v5 + "<br>")
}
</script>
+7
View File
@@ -0,0 +1,7 @@
<script>
function displayItems()
{
for (j = 0 ; j < displayItems.arguments.length ; ++j)
document.write(displayItems.arguments[j] + "<br>")
}
</script>
+14
View File
@@ -0,0 +1,14 @@
<script>
document.write(fixNames("the", "DALLAS", "CowBoys"))
function fixNames()
{
var s = ""
for (j = 0 ; j < fixNames.arguments.length ; ++j)
s += fixNames.arguments[j].charAt(0).toUpperCase() +
fixNames.arguments[j].substr(1).toLowerCase() + " "
return s.substr(0, s.length-1)
}
</script>
+17
View File
@@ -0,0 +1,17 @@
<script>
words = fixNames("the", "DALLAS", "CowBoys")
for (j = 0 ; j < words.length ; ++j)
document.write(words[j] + "<br>")
function fixNames()
{
var s = new Array()
for (j = 0 ; j < fixNames.arguments.length ; ++j)
s[j] = fixNames.arguments[j].charAt(0).toUpperCase() +
fixNames.arguments[j].substr(1).toLowerCase()
return s
}
</script>
+15
View File
@@ -0,0 +1,15 @@
<script>
function User(forename, username, password)
{
this.forename = forename
this.username = username
this.password = password
this.showUser = function()
{
document.write("Forename: " + this.forename + "<br>")
document.write("Username: " + this.username + "<br>")
document.write("Password: " + this.password + "<br>")
}
}
</script>
+16
View File
@@ -0,0 +1,16 @@
<script>
function User(forename, username, password)
{
this.forename = forename
this.username = username
this.password = password
this.showUser = showUser
}
function showUser()
{
document.write("Forename: " + this.forename + "<br>")
document.write("Username: " + this.username + "<br>")
document.write("Password: " + this.password + "<br>")
}
</script>
+15
View File
@@ -0,0 +1,15 @@
<script>
function User(forename, username, password)
{
this.forename = forename
this.username = username
this.password = password
User.prototype.showUser = function()
{
document.write("Forename: " + this.forename + "<br>")
document.write("Username: " + this.username + "<br>")
document.write("Password: " + this.password + "<br>")
}
}
</script>
+9
View File
@@ -0,0 +1,9 @@
<script>
numbers = []
numbers.push("One")
numbers.push("Two")
numbers.push("Three")
for (j = 0 ; j < numbers.length ; ++j)
document.write("Element " + j + " = " + numbers[j] + "<br>")
</script>
+9
View File
@@ -0,0 +1,9 @@
<script>
balls = {"golf": "Golf balls, 6",
"tennis": "Tennis balls, 3",
"soccer": "Soccer ball, 1",
"ping": "Ping Pong balls, 1 doz"}
for (ball in balls)
document.write(ball + " = " + balls[ball] + "<br>")
</script>
+23
View File
@@ -0,0 +1,23 @@
<script>
checkerboard = Array(
Array(' ', 'o', ' ', 'o', ' ', 'o', ' ', 'o'),
Array('o', ' ', 'o', ' ', 'o', ' ', 'o', ' '),
Array(' ', 'o', ' ', 'o', ' ', 'o', ' ', 'o'),
Array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '),
Array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '),
Array('O', ' ', 'O', ' ', 'O', ' ', 'O', ' '),
Array(' ', 'O', ' ', 'O', ' ', 'O', ' ', 'O'),
Array('O', ' ', 'O', ' ', 'O', ' ', 'O', ' '))
document.write("<pre>")
for (j = 0 ; j < 8 ; ++j)
{
for (k = 0 ; k < 8 ; ++k)
document.write(checkerboard[j][k] + " ")
document.write("<br>")
}
document.write("</pre>")
</script>
+10
View File
@@ -0,0 +1,10 @@
<script>
pets = ["Cat", "Dog", "Rabbit", "Hamster"]
pets.forEach(output)
function output(element, index, array)
{
document.write("Element at index " + index + " has the value " +
element + "<br>")
}
</script>
+7
View File
@@ -0,0 +1,7 @@
<script>
pets = ["Cat", "Dog", "Rabbit", "Hamster"]
document.write(pets.join() + "<br>")
document.write(pets.join(' ') + "<br>")
document.write(pets.join(' : ') + "<br>")
</script>
+11
View File
@@ -0,0 +1,11 @@
<script>
sports = ["Football", "Tennis", "Baseball"]
document.write("Start = " + sports + "<br>")
sports.push("Hockey");
document.write("After Push = " + sports + "<br>")
removed = sports.pop()
document.write("After Pop = " + sports + "<br>")
document.write("Removed = " + removed + "<br>")
</script>
+23
View File
@@ -0,0 +1,23 @@
<script>
numbers = []
for (j=1 ; j<6 ; ++j)
{
if (j == 2 || j == 5)
{
document.write("Processing 'todo' #" + j + "<br>")
}
else
{
document.write("Putting off 'todo' #" + j + " until later<br>")
numbers.push(j)
}
}
document.write("<br>Finished processing the priority tasks.")
document.write("<br>Commencing stored tasks, most recent first.<br><br>")
document.write("Now processing 'todo' #" + numbers.pop() + "<br>")
document.write("Now processing 'todo' #" + numbers.pop() + "<br>")
document.write("Now processing 'todo' #" + numbers.pop() + "<br>")
</script>
+5
View File
@@ -0,0 +1,5 @@
<script>
sports = ["Football", "Tennis", "Baseball", "Hockey"]
sports.reverse()
document.write(sports)
</script>
+21
View File
@@ -0,0 +1,21 @@
<script>
// Alphabetical sort
sports = ["Football", "Tennis", "Baseball", "Hockey"]
sports.sort()
document.write(sports + "<br>")
// Reverse alphabetical sort
sports = ["Football", "Tennis", "Baseball", "Hockey"]
sports.sort().reverse()
document.write(sports + "<br>")
// Ascending numeric sort
numbers = [7, 23, 6, 74]
numbers.sort(function(a,b){return a - b})
document.write(numbers + "<br>")
// Descending numeric sort
numbers = [7, 23, 6, 74]
numbers.sort(function(a,b){return b - a})
document.write(numbers + "<br>")
</script>