This commit is contained in:
2023-04-12 17:37:37 -05:00
parent e190e73b08
commit c798ae5486
39 changed files with 1315 additions and 41 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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}

View File

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

View File

@@ -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({
});
};

View File

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

View File

@@ -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
});

View File

@@ -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}

View File

@@ -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>

View File

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

View File

@@ -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>

View File

@@ -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

View File

@@ -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>