master
Caleb Fontenot 2023-04-12 17:37:37 +07:00
parent e190e73b08
commit c798ae5486
39 changed files with 1315 additions and 41 deletions

1
.gitignore vendored

@ -28,3 +28,4 @@
/Assignments/JavaScript/MP11_CalebFontenot/nbproject/private/
/Assignments/JavaScript/lab16js_CalebFontenot/nbproject/private/
/Assignments/JavaScript/MP12_CalebFontenot/nbproject/private/
/Assignments/JavaScript/lab17js_CalebFontenot/nbproject/private/

@ -0,0 +1,83 @@
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html>
<head>
<title>Dice</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<label id="valueOutput"></label><br>
<label id="score"></label><br>
<label id="PlayerText">Your Dice roll:</label><br>
<label id="playerDie"></label><br>
<label id="cpuText">CPU Dice roll:</label><br>
<label id="cpuDie"></label>
<label id="input"><input type="button" onclick="onClick()" value="Roll Die"/></label>
</body>
<script>
var cpuDieRoll = 0, playerDieRoll = 0, diceValues = {"playerDie": {}, "cpuDie": {}}, cpuTotalScore = 0, playerTotalScore = 0;
function onClick() {
playerDieRoll = rollDie("playerDie");
cpuDieRoll = rollDie("cpuDie");
writeValue(determineScore());
}
function printDie(dieNumber, elementId) {
let filename = "DieSet/Die" + dieNumber + ".png";
document.getElementById(elementId).innerHTML += "<image src=" + filename + ">";
//document.getElementById("wager").innerHTML = JSON.stringify(diceValues)
}
function rollDie(id) {
document.getElementById(id).innerHTML = "";
let diceTotal = 0;
for (let i = 0; i < 2; i++) {
let dieValue = Math.trunc((Math.random() * 6) + 1);
printDie(dieValue, id);
if (id === "playerDie") {
diceValues.playerDie["roll" + (i + 1)] = dieValue;
} else {
diceValues.cpuDie["roll" + (i + 1)] = dieValue;
}
diceTotal += dieValue;
}
return diceTotal;
}
function writeValue([playerRollScore, cpuRollScore]) {
document.getElementById("valueOutput").innerHTML = "Your Dice roll: " + playerRollScore + "; "
document.getElementById("valueOutput").innerHTML += "CPU Dice roll: " + cpuRollScore;
}
function determineScore() {
//Add rolls together
let playerRollScore = diceValues.playerDie["roll1"] + diceValues.playerDie["roll2"];
let cpuRollScore = diceValues.cpuDie["roll1"] + diceValues.cpuDie["roll2"];
let winString = "";
if (cpuDieRoll == playerDieRoll) {
winString = " It's a tie, no one won :("
} else {
if (playerRollScore > cpuRollScore) {
winString = " Player won!";
if (diceValues.playerDie["roll1"] == diceValues.playerDie["roll2"]) {
//double is rolled for player
playerRollScore = playerRollScore * 2;
winString = " Player won and rolled a double!";
}
playerTotalScore += playerRollScore;
} else {
winString = " CPU Won!"
if (diceValues.cpuDie["roll1"] == diceValues.cpuDie["roll2"]) {
//double is rolled for cpu
cpuRollScore = cpuRollScore * 2;
winString = " CPU won and rolled a double!"
}
cpuTotalScore += cpuRollScore;
}
}
document.getElementById("score").innerHTML = "Total Score: Player: " + playerTotalScore + "; CPU: " + cpuTotalScore + winString;
return [playerRollScore, cpuRollScore];
}
</script>
</html>

@ -1,40 +0,0 @@
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html>
<head>
<title>Dice</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<label id="valueOutput"></label><br>
<label id="cpuText">CPU Die:<br></label>
<label id="cpuDie"></label>
<label id="PlayerText">Your Die:<br></label>
<label id="playerDie"></label>
<br>
<label id="input"><input type="button" onclick="rollDie()" value="Roll Die"/></label>
</body>
<script>
function printDie(dieNumber, elementId) {
let filename = "DieSet/Die" + dieNumber + ".png";
document.getElementById(elementId).innerHTML += "<image src=" + filename + ">";
}
function rollDie() {
document.getElementById("playerDie").innerHTML = "";
let diceTotal = 0;
for (let i =0; i < 2; i++) {
let dieValue = Math.trunc((Math.random() * 6) + 1);
printDie(dieValue, "playerDie");
diceTotal += dieValue;
}
writeValue(diceTotal);
}
function writeValue(yourDiceRoll) {
document.getElementById("valueOutput").innerHTML = "Your Dice roll: " + yourDiceRoll
}
</script>
</html>

@ -0,0 +1,108 @@
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html>
<head>
<title>Dice</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<label id="valueOutput"></label><br>
<label id="score"></label><br>
<label id="wager"></label><br>
<label id="poolStats"></label><br>
<label id="PlayerText">Your Dice roll:</label><br>
<label id="playerDie"></label><br>
<label id="cpuText">CPU Dice roll:</label><br>
<label id="cpuDie"></label><br>
<label>Enter the amount of money to add to the pool (aka the "kitty"): <input id="wagerAmount" type="number"><input type="button" id="makeBet" onclick="determineWager();" value="Make bet"/></label><br>
<label id="input"><input type="button" id="rollDie" onclick="onClick()" value="Roll Die"/></label>
</body>
<script>
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
var cpuDieRoll = 0, playerDieRoll = 0, diceValues = {"playerDie": {}, "cpuDie": {}}, cpuTotalScore = 0, playerTotalScore = 0, moneyPool = 0;
document.getElementById("rollDie").hidden = true;
function onClick() {
playerDieRoll = rollDie("playerDie");
cpuDieRoll = rollDie("cpuDie");
writeValue(determineScore());
document.getElementById("rollDie").hidden = true;
}
function determineWager() {
let playerWager = parseInt(document.getElementById("wagerAmount").value);
let cpuWager = 0;
let determineCpuMove = Math.trunc((Math.random() * 3));
switch (determineCpuMove) {
case 0: // Match bet
document.getElementById("wager").innerHTML = "CPU: I match your bet! 😏";
cpuWager = playerWager;
break;
case 1: // fold
document.getElementById("wager").innerHTML = "CPU: Okay, I'll fold. 😔";
playerTotal = moneyPool;
cpuWager = 0;
moneyPool = 0;
break;
case 2: // Raise bet
document.getElementById("wager").innerHTML = "CPU: I'll raise your bet! 😏";
cpuWager = (playerWager * 1.5);
break;
}
moneyPool = (cpuWager + playerWager);
document.getElementById("poolStats").innerHTML = "Pool: " + formatter.format(moneyPool);
document.getElementById("rollDie").hidden = false;
}
function printDie(dieNumber, elementId) {
let filename = "DieSet/Die" + dieNumber + ".png";
document.getElementById(elementId).innerHTML += "<image src=" + filename + ">";
//document.getElementById("wager").innerHTML = JSON.stringify(diceValues)
}
function rollDie(id) {
document.getElementById(id).innerHTML = "";
let diceTotal = 0;
for (let i = 0; i < 2; i++) {
let dieValue = Math.trunc((Math.random() * 6) + 1);
printDie(dieValue, id);
if (id === "playerDie") {
diceValues.playerDie["roll" + (i + 1)] = dieValue;
} else {
diceValues.cpuDie["roll" + (i + 1)] = dieValue;
}
diceTotal += dieValue;
}
return diceTotal;
}
function writeValue([playerRollScore, cpuRollScore]) {
document.getElementById("valueOutput").innerHTML = "Your Dice roll: " + playerRollScore + "; "
document.getElementById("valueOutput").innerHTML += "CPU Dice roll: " + cpuRollScore;
}
function determineScore() {
//Add rolls together
let playerRollScore = diceValues.playerDie["roll1"] + diceValues.playerDie["roll2"];
let cpuRollScore = diceValues.cpuDie["roll1"] + diceValues.cpuDie["roll2"];
let winString = "";
if (cpuDieRoll == playerDieRoll) {
winString = " It's a tie, no one won :("
} else {
if (playerRollScore > cpuRollScore) {
winString = " Player won!";
playerTotalScore += moneyPool;
moneyPool = 0;
} else {
winString = " CPU Won!"
cpuTotalScore = moneyPool;
moneyPool = 0;
}
}
document.getElementById("score").innerHTML = "Total Score: Player: " + formatter.format(playerTotalScore) + "; CPU: " + formatter.format(cpuTotalScore) + winString;
return [playerRollScore, cpuRollScore];
}
</script>
</html>

@ -2,4 +2,3 @@ file.reference.lab16js_CalebFontenot-public_html=public_html
file.reference.lab16js_CalebFontenot-test=test
files.encoding=UTF-8
site.root.folder=${file.reference.lab16js_CalebFontenot-public_html}
test.folder=${file.reference.lab16js_CalebFontenot-test}

@ -0,0 +1,3 @@
{
"directory": "public_html/bower_components"
}

@ -0,0 +1,9 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/ClientSide/Gruntfile.js to edit this template
*/
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
});
};

@ -0,0 +1,13 @@
{
"name": "lab17js_CalebFontenot",
"version": "1.0.0",
"main": "path/to/main.css",
"ignore": [
".jshintrc",
"**/*.txt"
],
"dependencies": {
},
"devDependencies": {
}
}

@ -0,0 +1,10 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/ClientSide/gulpfile.js to edit this template
*/
var gulp = require('gulp');
gulp.task('default', function () {
// place code for your default task here
});

@ -0,0 +1,5 @@
file.reference.lab17js_CalebFontenot-public_html=public_html
file.reference.lab17js_CalebFontenot-test=test
files.encoding=UTF-8
site.root.folder=${file.reference.lab17js_CalebFontenot-public_html}
test.folder=${file.reference.lab17js_CalebFontenot-test}

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.clientproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/clientside-project/1">
<name>lab17js_CalebFontenot</name>
</data>
</configuration>
</project>

@ -0,0 +1,8 @@
{
"name": "lab17js_CalebFontenot",
"version": "1.0.0",
"keywords": ["util", "functional", "server", "client", "browser"],
"author": "caleb",
"contributors": [],
"dependencies": {}
}

@ -0,0 +1,229 @@
<html>
<head>
<title>Example 8.14</title>
<script type="text/javascript">
function getRings()
{
var rings = new Array();
document.getElementById('ring_inventory').innerHTML = ("");
var numRings = parseInt(prompt("How many rings are in the inventory now?"));
for (i = 0; i <= (numRings - 1); i++)
{
rings[i] = prompt("Enter ring # " + (i + 1) +":");
}
displayRings(rings);
addRings(rings);
deleteRings(rings);
}
function getBracelets()
{
var bracelets = new Array();
document.getElementById('bracelet_inventory').innerHTML = ("");
var numRings = parseInt(prompt("How many bracelets are in the inventory now?"));
for (i = 0; i <= (numRings - 1); i++)
{
rings[i] = prompt("Enter bracelet # " + (i + 1) +":");
}
displayBracelets(bracelets);
addBracelets(bracelets);
deleteBracelets(bracelets);
}
function getPendants()
{
var pendants = new Array();
document.getElementById('pendant_inventory').innerHTML = ("");
var numRings = parseInt(prompt("How many pendants are in the inventory now?"));
for (i = 0; i <= (numRings - 1); i++)
{
pendants[i] = prompt("Enter pendant # " + (i + 1) +":");
}
displayPendants(pendants);
addPendants(pendants);
deletePendants(pendants);
}
function displayRings(rings)
{
var r = rings.length;
for (i = 0; i <= (r - 1); i++)
{
document.getElementById('ring_inventory').innerHTML = ("<h3>" + rings + "</h3>");
}
}
function displayBracelets(bracelets)
{
var r = bracelets.length;
for (i = 0; i <= (r - 1); i++)
{
document.getElementById('bracelet_inventory').innerHTML = ("<h3>" + bracelets + "</h3>");
}
}
function displayPendants(pendants)
{
var r = pendants.length;
for (i = 0; i <= (r - 1); i++)
{
document.getElementById('pendant_inventory').innerHTML = ("<h3>" + pendants + "</h3>");
}
}
function addRings(rings)
{
var r = rings.length;
numAdd = parseInt(prompt("If you want to add to the inventory, enter the number of rings you want to add (or enter 0):"));
for (i = 0; i <= (numAdd - 1); i++)
{
if (numAdd == 0)
break;
var newRing = prompt("Enter a ring to add:");
rings.push(newRing);
}
displayRings(rings);
}
function addBracelets(bracelets)
{
var r = bracelets.length;
numAdd = parseInt(prompt("If you want to add to the inventory, enter the number of bracelets you want to add (or enter 0):"));
for (i = 0; i <= (numAdd - 1); i++)
{
if (numAdd == 0)
break;
var newBracelets = prompt("Enter a bracelet to add:");
bracelets.push(newBracelets);
}
displayBracelets(bracelets);
}
function addPendants(pendants)
{
var r = pendants.length;
numAdd = parseInt(prompt("If you want to add to the inventory, enter the number of pendants you want to add (or enter 0):"));
for (i = 0; i <= (numAdd - 1); i++)
{
if (numAdd == 0)
break;
var newPendants = prompt("Enter a pendant to add:");
pendants.push(newPendants);
}
displayPendants(pendants);
}
function deleteRings(rings)
{
var r = rings.length;
numSubt = parseInt(prompt("If you want to subtract from the inventory, enter the number of rings you want to subtract (or enter 0):"));
for (i = 0; i <= (numSubt - 1); i++)
{
if (numSubt == 0)
break;
var oldRings = prompt("Enter a ring to delete:");
var flag = 0;
for (j = 0; j <= (r - 1); j++)
{
if (rings[j] == oldRings)
{
rings.splice(j,1);
flag = 1;
}
}
if (flag == 0)
{
alert(oldRings + " is not part of the inventory.");
break;
}
}
displayRings(rings);
}
function deletePendants(pendants)
{
var r = pendants.length;
numSubt = parseInt(prompt("If you want to subtract from the inventory, enter the number of pendants you want to subtract (or enter 0):"));
for (i = 0; i <= (numSubt - 1); i++)
{
if (numSubt == 0)
break;
var oldPendants = prompt("Enter a pendant to delete:");
var flag = 0;
for (j = 0; j <= (r - 1); j++)
{
if (pendants[j] == oldPendants)
{
pendants.splice(j,1);
flag = 1;
}
}
if (flag == 0)
{
alert(oldPendants + " is not part of the inventory.");
break;
}
}
displayPendants(pendants);
}
function deleteBracelets(bracelets)
{
var r = bracelets.length;
numSubt = parseInt(prompt("If you want to subtract from the inventory, enter the number of bracelets you want to subtract (or enter 0):"));
for (i = 0; i <= (numSubt - 1); i++)
{
if (numSubt == 0)
break;
var oldBracelets = prompt("Enter a bracelet to delete:");
var flag = 0;
for (j = 0; j <= (r - 1); j++)
{
if (bracelets[j] == oldBracelets)
{
rings.splice(j,1);
flag = 1;
}
}
if (flag == 0)
{
alert(oldBracelets + " is not part of the inventory.");
break;
}
}
displayBracelets(bracelets);
}
</script>
<style type="text/css">
<!--
body {
margin: 20pt;
padding: 5%;
width: 80%;
}
.div_width {
width: 33%;
float: left;
}
-->
</style>
</head>
<body>
<div id="container">
<img src="images/jewel_box1.jpg" class="floatleft" />
<h1 align="center">Jackie's Jewelry Inventory</h1>
<div style ="clear:both;"></div>
<div = "content" width = "800">
<div class="div_width" id="rings">
<input type="button" value="Enter your inventory of rings" onclick="getRings()"; />
<h2>Ring Inventory</h2>
<div id = "ring_inventory"></div>
</div>
<div class="div_width" id="bracelets">
<input type="button" value="Enter your inventory of bracelets" onclick="getBracelets()"; />
<h2>Bracelet Inventory</h2>
<div id = "bracelet_inventory"></div>
</div>
<div id="pendants" >
<input type="button" value="Enter your inventory of pendants" onclick="getPendants()"; />
<h2 class="div_width">Pendant Inventory</h2>
<div id = "pendant_inventory"></div>
</div>
</div>
</div>
</body>
</html>

@ -0,0 +1,12 @@
function getRings()
{
var rings = new Array("gold band", "silver band", "turquoise inlay", "emerald stone", "ruby stone");
var r = rings.length;
r_title = "Ring Inventory";
document.getElementById('ring_head').innerHTML = r_title;
for (i = 0; i <= (r - 1); i++)
{
document.getElementById('ring_inventory').innerHTML = (rings[i] + "<br /> ");
}
document.write("</table>");
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

@ -0,0 +1,48 @@
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/html.html to edit this template
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<label id="numArray"></label><br>
<label id="averageLabel"></label><br>
<label id="arraySquare"></label><br>
<label id="stdDevLabel"></label><br>
<label id="numCountLabel"></label><br>
<label id="sumLabel"></label>
</body>
<script>
var numberArray = [];
do {
var userInput = prompt("Please enter a number. Type q/Q to quit.");
if (userInput.toLowerCase() != "q" && userInput != "") {
numberArray.push(parseInt(userInput));
console.log(numberArray);
}
} while (userInput.toLowerCase() != "q");
//Let's calculate stuff!
let average, arraySum = 0, arraySquare = 0, stdDev = 0;
for (let i = 0; i < numberArray.length; ++i) {
arraySum += numberArray[i]; // sum
}
average = arraySum / numberArray.length; // Average
for (let i = 0; i < numberArray.length; ++i) {
arraySquare += Math.pow(numberArray[i] - average, 2);
}
stdDev = Math.sqrt(arraySquare, (numberArray - 1));
document.getElementById("numArray").innerHTML = "Number Array: " + numberArray;
document.getElementById("averageLabel").innerHTML = "Average: " + average;
document.getElementById("arraySquare").innerHTML = "Square of elements in array: " + arraySquare;
document.getElementById("stdDevLabel").innerHTML = "Standard Deviation: " + stdDev;
document.getElementById("numCountLabel").innerHTML = "Number of Elements in array: " + numberArray.length;
document.getElementById("sumLabel").innerHTML = "Sum of elements in array: " + arraySum;
</script>
</html>

Binary file not shown.

Binary file not shown.

@ -0,0 +1,31 @@
<html>
<head>
<title>Example 8.10</title>
<script type="text/javascript">
function getColors()
{
var ribbons = new Array("black", "white", "brown", "blue", "red");
var r = ribbons.length;
document.write("<table align = 'center'><tr><td>");
document.write("<br /> Old colors:</td></tr><tr><td>");
for (i = 0; i <= (r - 1); i++)
{
document.write(ribbons[i] + " ");
}
document.write("</td></tr><tr><td>Original length: " + r + "</td></tr><tr><td>");
ribbons.push("purple","green");
r = ribbons.length;
document.write("New colors:</td></tr><tr><td>");
for (i = 0; i <= (r - 1); i++)
{
document.write(ribbons[i] + " ");
}
document.write("</td></tr><tr><td>New length: " + r + "</td></tr>");
document.write("</table>");
}
</script>
</head>
<body>
<button onclick="getColors()">See ribbon colors</button>
</body></html>

@ -0,0 +1,31 @@
<html>
<head>
<title>Example 8.11</title>
<script type="text/javascript">
function getColors()
{
var ribbons = new Array("black", "white", "brown", "blue", "red");
var r = ribbons.length;
document.write("<table align = 'center'><tr><td>");
document.write("<br /> Old colors:</td></tr><tr><td>");
for (i = 0; i <= (r - 1); i++)
{
document.write(ribbons[i] + " ");
}
document.write("</td></tr><tr><td>Original length: " + r + "</td></tr><tr><td>");
ribbons.unshift("purple","green");
r = ribbons.length;
document.write("New colors:</td></tr><tr><td>");
for (i = 0; i <= (r - 1); i++)
{
document.write(ribbons[i] + " ");
}
document.write("</td></tr><tr><td>New length: " + r + "</td></tr>");
document.write("</table>");
}
</script>
</head>
<body>
<button onclick="getColors()">See ribbon colors</button>
</body></html>

@ -0,0 +1,31 @@
<html>
<head>
<title>Example 8.12</title>
<script type="text/javascript">
function getColors()
{
var ribbons = new Array("black", "white", "brown", "blue", "red");
var r = ribbons.length;
document.write("<table align = 'center'><tr><td>");
document.write("<br /> Old colors:</td></tr><tr><td>");
for (i = 0; i <= (r - 1); i++)
{
document.write(ribbons[i] + " ");
}
document.write("</td></tr><tr><td>Original length: " + r + "</td></tr><tr><td>");
ribbons.splice(2,0,"mauve","teal","ecru","buttercup");
r = ribbons.length;
document.write("New colors:</td></tr><tr><td>");
for (i = 0; i <= (r - 1); i++)
{
document.write(ribbons[i] + " ");
}
document.write("</td></tr><tr><td>New length: " + r + "</td></tr>");
document.write("</table>");
}
</script>
</head>
<body>
<button onclick="getColors()">See ribbon colors</button>
</body></html>

@ -0,0 +1,31 @@
<html>
<head>
<title>Example 8.13</title>
<script type="text/javascript">
function getColors()
{
var ribbons = new Array("black", "white", "mauve","teal","ecru","buttercup","brown", "blue", "red");
var r = ribbons.length;
document.write("<table align = 'center'><tr><td>");
document.write("<br /> Old colors:</td></tr><tr><td>");
for (i = 0; i <= (r - 1); i++)
{
document.write(ribbons[i] + " ");
}
document.write("</td></tr><tr><td>Original length: " + r + "</td></tr><tr><td>");
ribbons.splice(1,2);
r = ribbons.length;
document.write("New colors:</td></tr><tr><td>");
for (i = 0; i <= (r - 1); i++)
{
document.write(ribbons[i] + " ");
}
document.write("</td></tr><tr><td>New length: " + r + "</td></tr>");
document.write("</table>");
}
</script>
</head>
<body>
<button onclick="getColors()">See ribbon colors</button>
</body></html>

@ -0,0 +1,107 @@
<html>
<head>
<title>Example 8.14</title>
<script type="text/javascript">
function getRings()
{
var rings = new Array();
document.getElementById('ring_inventory').innerHTML = ("");
var numRings = parseInt(prompt("How many rings are in the inventory now?"));
for (i = 0; i <= (numRings - 1); i++)
{
rings[i] = prompt("Enter ring # " + (i + 1) +":");
}
displayRings(rings);
addRings(rings);
deleteRings(rings);
}
function displayRings(rings)
{
var r = rings.length;
for (i = 0; i <= (r - 1); i++)
{
document.getElementById('ring_inventory').innerHTML = ("<h3>" + rings + "</h3>");
}
}
function addRings(rings)
{
var r = rings.length;
numAdd = parseInt(prompt("If you want to add to the inventory, enter the number of rings you want to add (or enter 0):"));
for (i = 0; i <= (numAdd - 1); i++)
{
if (numAdd == 0)
break;
var newRing = prompt("Enter a ring to add:");
rings.push(newRing);
}
displayRings(rings);
}
function deleteRings(rings)
{
var r = rings.length;
numSubt = parseInt(prompt("If you want to subtract from the inventory, enter the number of rings you want to subtract (or enter 0):"));
for (i = 0; i <= (numSubt - 1); i++)
{
if (numSubt == 0)
break;
var oldRing = prompt("Enter a ring to delete:");
var flag = 0;
for (j = 0; j <= (r - 1); j++)
{
if (rings[j] == oldRing)
{
rings.splice(j,1);
flag = 1;
}
}
if (flag == 0)
{
alert(oldRing + " is not part of the inventory.");
break;
}
}
displayRings(rings);
}
</script>
<style type="text/css">
<!--
body {
margin: 20pt;
padding: 5%;
width: 80%;
}
.div_width {
width: 33%;
float: left;
}
-->
</style>
</head>
<body>
<div id="container">
<img src="images/jewel_box1.jpg" class="floatleft" />
<h1 align="center">Jackie's Jewelry Inventory</h1>
<div style ="clear:both;"></div>
<div = "content" width = "800">
<div class="div_width" id="rings">
<input type="button" value="Enter your inventory of rings" onclick="getRings()"; />
<h2>Ring Inventory</h2>
<div id = "ring_inventory"></div>
</div>
<div class="div_width" id="bracelets">
<input type="button" value="Enter your inventory of bracelets" onclick="getBracelets()"; />
<h2>Bracelet Inventory</h2>
<div id = "bracelet_inventory"></div>
</div>
<div id="pendants" >
<input type="button" value="Enter your inventory of pendants" onclick="getPendants()"; />
<h2 class="div_width">Pendant Inventory</h2>
<div id = "pendant_inventory"></div>
</div>
</div>
</div>
</body>
</html>

@ -0,0 +1,12 @@
function getRings()
{
var rings = new Array("gold band", "silver band", "turquoise inlay", "emerald stone", "ruby stone");
var r = rings.length;
r_title = "Ring Inventory";
document.getElementById('ring_head').innerHTML = r_title;
for (i = 0; i <= (r - 1); i++)
{
document.getElementById('ring_inventory').innerHTML = (rings[i] + "<br /> ");
}
document.write("</table>");
}

@ -0,0 +1,27 @@
<html>
<head>
<title>Example 8.16</title>
<script type="text/javascript">
var myarray = new Array(6); //allocates 6 rows to the array
for (i = 0; i < 6; i++)
{
myarray[i] = new Array(5); //allocates 5 columns each row
}
document.write("Ex 8.16: 2-D array: <br />");
for (var i = 0; i < 6; i++)
{
for (var j = 0; j < 5; j++)
{
myarray[i][j] = prompt("Enter value for row " + i + ", column " + j +":");
document.write(myarray[i][j] + " ");
}
document.write("<br />");
}
</script>
</head>
<body>
</body>
</html>

@ -0,0 +1,58 @@
<html>
<head>
<title>Example 8.17</title>
<script type="text/javascript">
function setup()
{
cells = new Array([document.getElementById("cell00"),document.getElementById("cell01"),
document.getElementById("cell02")],[document.getElementById("cell10"),
document.getElementById("cell11"), document.getElementById("cell12")],
[document.getElementById("cell20"),document.getElementById("cell21"),
document.getElementById("cell22")] );
placeValues();
}
// function to place values in cells
function placeValues()
{
for ( rows = 0; rows < 3; rows++ )
{
for ( var cols = 0; cols< 3; cols++ )
{
cells[rows][cols].innerHTML = prompt("Enter a value:");
}
}
}
</script>
<style type="text/css">
<!--
table { border: solid #4f81bd; }
body { margin: 10ex; color: #4f81bd; font-weight: bold; }
td {
font-size: 18px; color: #4f81bd; font-weight: bold; margin: 10%;
padding: 5px; line-height: 120%; width: 75pt; height: 25pt;
text-align: center;
}
-->
</style>
</head>
<body onload ="setup()">
<h1>Loading a 2-Dimensional Array</h1>
<table id = "myTable" border = "1">
<tr>
<td> <span id = "cell00" />cell 00 </td>
<td> <span id = "cell01" />cell 01 </td>
<td> <span id = "cell02" /> cell 02 </td>
</tr>
<tr>
<td> <span id = "cell10" />cell 10 </td>
<td> <span id = "cell11" />cell 11 </td>
<td> <span id = "cell12" />cell 12 </td>
</tr>
<tr>
<td> <span id = "cell20" />cell 20 </td>
<td> <span id = "cell21" />cell 21 </td>
<td> <span id = "cell22" />cell 22 </td>
</tr>
</table>
</body>
</html>

@ -0,0 +1,23 @@
<html>
<head>
<title>Example 8.2</title>
<script type="text/javascript">
var numbers = new Array(3);
numbers[0] = 4;
numbers[1] = 5;
numbers[2] = 6;
var result = 0;
result = numbers[0] + numbers[1];
document.write("a): result = " + result + "<br />");
result = numbers[1] * numbers[2];
document.write("b): result = " + result + "<br />");
result = numbers[2] % numbers[0];
document.write("c): result = " + result + "<br />");
</script>
</head>
<body>
</body>
</html>

@ -0,0 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Example 8.3</title>
<script type="text/javascript">
var food = new Array();
food[0] = "pizza";
food[1] = "hamburger";
document.write("Original length: " + food.length + "<br />");
food[2] = "chips";
food[3] = "cake";
document.write("New length: " + food.length);
</script>
</head>
<body>
</body>
</html>

@ -0,0 +1,19 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Example 8.6</title>
<script type="text/javascript">
var names = new Array();
var numStud = prompt("How many students are in the class: ");
numStud = parseInt(numStud);
var i = 0;
for (i = 0; i <= numStud - 1; i++)
{
names[i]= prompt("Enter the student's name: ");
}
</script>
</head>
<body>
</body>
</html>

@ -0,0 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Example 8.7</title>
<script type="text/javascript">
var names = new Array();
var numStud = prompt("How many students are in the class? ");
numStud = parseInt(numStud);
var i = 0;
for (i = 0; i <= numStud - 1; i++)
{
names[i]= prompt("Enter the student's name: ");
document.write("Name of student " + (i + 1) + ": " + names[i] + "<br />");
}
</script>
</head>
<body>
</body></html>

@ -0,0 +1,33 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Example 8.8</title>
<script type="text/javascript">
var names = new Array();
var grades = new Array();
var high = 0;
var index = 0;
var k = 0;
while (names[k] != "*")
{
names[k]= prompt("Enter the student's name or enter an asterisk (*) when you are done: ");
if (names[k] == "*")
{
break;
}
grades[k]= prompt("Enter the student's grade: ");
grades[k] = parseFloat(grades[k]);
document.write("Name of student " + (k + 1) + ": " + names[k] + " grade: " + grades[k] + "<br />");
if (grades[k] > high)
{
index = k;
high = grades[index];
}
k = k + 1;
}
document.write("The highest grade in the class is: " + grades[index] + "<br />");
document.write(names[index] + " is the high-achieving student! <br />");
</script>
</head>
<body>
</body></html>

@ -0,0 +1,37 @@
<html>
<head>
<title>Example 8.9</title>
<script type="text/javascript">
var scores = new Array();
var sum = 0;
var count1 = 0;
var count2 = 0;
var count = 0;
var average = 0;
while (scores[count1] != 999)
{
scores[count1]= prompt("Enter the student's grade or enter 999 when you are done: ");
scores[count1] = parseFloat(scores[count1]);
if (scores[count1] == 999)
{
break;
}
sum = sum + scores[count1];
count1 = count1 + 1;
}
average = sum / count1;
for (count = 0; count < count1; count++)
{
if (scores[count] > average)
{
count2 = count2 + 1;
}
}
document.write("The average is: " + average.toFixed(2) + "<br />");
document.write("The number above the average is: " + count2 + "<br />");
document.write("The number below the average is: " + (count1 - count2) + "<br />");
</script>
</head>
<body>
</body></html>

@ -0,0 +1,122 @@
body { background-color: #000040;
background-image: url(background.gif);
color: #88ffff;
font-family: Verdana, Arial, sans-serif;
}
#container { margin-left: auto;
margin-right: auto;
width:80%;
min-width:700px;
}
#logo {
text-align:center;
margin: 0;
font-family: Geneva, Arial, Helvetica, sans-serif;
padding-top: 30px;
padding-bottom: 20px;
}
#nav {
float: left;
width: 200px;
padding-top: 10px;
text-align:left;
color: #88FFFF;
font-size: 12px;
}
#nav a {text-decoration:none;
margin: 15px;
display: block;
color: #88FFFF;
font-size: 12px;
}
#content {
margin-left: 150px;
padding: 30px;
overflow:auto;
border: medium groove #88FFFF;
line-height: 135%;
}
.floatright {padding-left:20px;
float:right;
}
.floatleft {
float:left;
padding: 30px 0px 20px;
}
#footer { font-size: .60em;
font-style: italic;
text-align: center;
border-top: 2px double #000040;
padding-top: 20px;
padding-bottom: 20px;
}
h2 { text-transform: uppercase;
color: #88ffff;
font-size: 1.2em;
border-bottom: 1px none;
margin-right: 20px;
}
h3 {
color: #88ffff;
font-size: 1.2em;
border-bottom: 1px solid #000000;
margin-right: auto;
text-align: left;
padding-top: 10px;
padding-right: 20px;
padding-bottom: 10px;
padding-left: 20px;
line-height: 120%;
}
.details { padding-left:20%;
padding-right:20%;
}
img {border:0; }
.content {
margin: 20px;
padding: 20px;
height: 3700px;
width: 500px;
}
a {text-decoration:none;
margin: 15px;
display: block;
color: #88FFFF;
font-size: 12px;
}
a:hover {
color: #000040;
background-color: #88ffff;
}
span {
font-size: 20px;
font-weight: bold;
font-family: "Courier New", Courier, mono;
color: #88ffff;
background-position: center center;
text-align: center;
vertical-align: middle;
}
table {
border-collapse: collapse
}
td {
border: 2px solid #88ffff;
width: 5em;
color: #88ffff;
text-align: center;
}
.nobdr {
border: none;
cell-padding: 5px;
}

@ -0,0 +1,135 @@
<html>
<head>
<title>Greg's Gambits | Greg's 15</title>
<link href="greg.css" rel="stylesheet" type="text/css" />
<script type = "text/javascript">
var cells;
var swapped;
function setup()
{
cells = new Array([document.getElementById("cell00"),document.getElementById("cell01"), document.getElementById("cell02"), document.getElementById("cell03")],
[document.getElementById("cell10"), document.getElementById("cell11"),document.getElementById("cell12"), document.getElementById("cell13")],
[document.getElementById("cell20"), document.getElementById("cell21"),document.getElementById("cell22"), document.getElementById("cell23")],
[document.getElementById("cell30"), document.getElementById("cell31"), document.getElementById("cell32"), document.getElementById("cell33")]);
placeNumbers();
}
function placeNumbers()
{
var numbers = new Array();
for (var i=0; i<=16; i++)
numbers[i] = i;
var randomLoc;
var temp;
for (i= 0; i < 16 ; i++)
{
randomLoc = Math.floor(Math.random()* 15 + 1);
temp = numbers[i];
numbers[i] = numbers[randomLoc];
numbers[randomLoc] = temp;
}
i = 0;
for (var rows = 0; rows < 4; rows++)
{
for (var cols = 0; cols< 4; cols++)
{
if (numbers[i] != 0)
cells[rows][cols].innerHTML = numbers[i];
else
cells[rows][cols].innerHTML = "";
++i;
}
}
}
function doClick(row, col)
{
var top = row - 1;
var bottom = row + 1;
var left = col - 1;
var right = col + 1;
swapped = false;
if(top != -1 && cells[top][col].innerHTML == "")
swap(cells[row][col], cells[top][col]);
else
if(right != 4 && cells[row][right].innerHTML == "")
swap(cells[row][col], cells[row][right]);
else
if(bottom != 4 && cells[bottom][col].innerHTML == "")
swap(cells[row][col], cells[bottom][col]);
else
if (left != -1 && cells[row][left].innerHTML == "")
swap(cells[row][col], cells[row][left]);
else
alert("Illegal move.");
checkWinner();
}
function swap(firstCell, secondCell)
{
swapped = true;
secondCell.innerHTML = firstCell.innerHTML;
firstCell.innerHTML = "";
}
function checkWinner()
{
var win = true;
for (var i = 0; i < 4; i++)
{
for (var j = 0; j < 4; j++)
{
if (!(cells[i][j].innerHTML == i*4 + j + 1))
if (!(i == 3 && j == 3))
win = false;
}
}
if (win)
{
alert("Congratulations! You won!");
if (window.prompt("Play again?", "yes"))
placeNumbers();
}
}
</script>
</head>
<body onload ="setup()">
<div id="container">
<img src="images/superhero.jpg" class="floatleft" />
<h1 id="logo"><em>Greg's 15</em></h1>
<p>&nbsp;</p>
<div id="nav">
<p><a href="index.html">Home</a>
<a href="greg.html">About Greg</a>
<a href="play_games.html">Play a Game</a>
<a href="sign.html">Sign In</a>
<a href="contact.html">Contact Us</a></p>
</div>
<div id="content">
<p><input type="button" value = "Start the game" onclick="setup();" /></p>
<p>You can move any number into an empty spot by moving up, down,right, or left. Diagonal moves are not allowed. The object is to get all the numbers into correct order, from 1 through 15 with the empty space at the end. </p>
<table width = "60%" align = "center">
<tr>
<td height = "60"><span onclick = "doClick(0,0)" id = "cell00" />&nbsp;</td>
<td><span onclick = "doClick(0,1)" id = "cell01" />&nbsp;</td>
<td><span onclick = "doClick(0,2)" id = "cell02" />&nbsp</td>
<td><span onclick = "doClick(0,3)" id = "cell03" />&nbsp;</td>
</tr> <tr>
<td height = "60"><span onclick = "doClick(1,0)" id = "cell10" />&nbsp;</td>
<td><span onclick = "doClick(1,1)" id = "cell11" />&nbsp;</td>
<td><span onclick = "doClick(1,2)" id = "cell12" />&nbsp;</td>
<td><span onclick = "doClick(1,3)" id = "cell13" />&nbsp;</td>
</tr> <tr>
<td height = "60"><span onclick = "doClick(2,0)" id = "cell20" />&nbsp;</td>
<td><span onclick = "doClick(2,1)" id = "cell21" />&nbsp;</td>
<td><span onclick = "doClick(2,2)" id = "cell22" />&nbsp;</td>
<td><span onclick = "doClick(2,3)" id = "cell23" />&nbsp;</td>
</tr> <tr>
<td height = "60"><span onclick = "doClick(3,0)" id = "cell30" />&nbsp;</td>
<td><span onclick = "doClick(3,1)" id = "cell31" />&nbsp;</td>
<td><span onclick = "doClick(3,2)" id = "cell32" />&nbsp;</td>
<td><span onclick = "doClick(3,3)" id = "cell33" />&nbsp;</td>
</tr>
</table>
</div>
<div id="footer">Copyright &copy; 2013 Greg's Gambits<br />
<a href="mailto:yourfirstname@yourlastname.com">
yourfirstname@yourlastname.com</a></div>
</div>
</body></html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

@ -0,0 +1,44 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Greg's Gambits | Games Menu</title>
<link href="greg.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="container">
<img src="images/superhero.jpg" width="120" height="120" class="floatleft" />
<h1 id="logo"><em>Play A Game</em></h1>
<div style ="clear:both;"></div>
<div id="nav">
<p><a href="index.html">Home</a>
<a href="greg.html">About Greg</a>
<a href="play_games.html">Play a Game</a>
<a href="sign.html">Sign In</a>
<a href="contact.html">Contact Us</a></p>
</div>
<div id="content">
<p>Menu of Available Games </p>
<table width="90%" border="0" cellpadding="5">
<tr>
<td width="50%"><a href="greg_tales.html">Greg's Tales</a> </td>
<td width="50%"><a href ="gregs_fortune.html">Madame Vadoma Sees All</a></td>
</tr>
<tr>
<td width="50%"><a href="greg_encoder.html">The Secret Message Encoder</a> </td>
<td><a href = "greg_battle.html">Battle the Evil Troll</a></td>
</tr>
<tr>
<td><a href="greg_game_15.html">The Game of 15</a> </td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
</div>
<div id="footer">Copyright &copy; 2013 Greg's Gambits<br />
<a href="mailto:yourfirstname@yourlastname.com">yourfirstname@yourlastname.com</a></div>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB