Finish MP13
This commit is contained in:
parent
414a06957d
commit
2dc89a3b93
@ -5,17 +5,85 @@ Click nbfs://nbhost/SystemFileSystem/Templates/ClientSide/html.html to edit this
|
|||||||
-->
|
-->
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>TODO supply a title</title>
|
<title>Problem 4</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<style>
|
||||||
|
table, th, td {
|
||||||
</body>
|
border: 1px solid;
|
||||||
<script>
|
|
||||||
function tableBuilder(field) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<div id="tableDiv"></div>
|
||||||
|
<!div><!input type="button" onclick="tableBuilder()" value="Build table"><!/div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const formatter = new Intl.NumberFormat('en-US', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: 'USD',
|
||||||
|
});
|
||||||
|
let itemPrices = [];
|
||||||
|
let multipliers = [1, 1, 1, 1, 1, 1, 1, 1];
|
||||||
|
let ids = ["notebookVal", "penVal", "mechanicalPencilVal", "refilPackVal", "laptopCaseVal", "cellphoneCaseVal", "threeRingBinderVal", "threeHolePaperRefilVal"];
|
||||||
|
tableBuilder();
|
||||||
|
function getTotal() {
|
||||||
|
let total = 0;
|
||||||
|
for (let i = 0; i < itemPrices.length; ++i) {
|
||||||
|
total += itemPrices[i];
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
function updateMultiplier(id) {
|
||||||
|
let basePrices = [5.95, 4.95, 2.95, 0.98, 29.99, 18.99, 6.95, 2.00];
|
||||||
|
let multValue;
|
||||||
|
// Set item values to base prices on page load.
|
||||||
|
if (id == undefined) {
|
||||||
|
multValue = -1; // This prevents the function from crashing when the page loads.
|
||||||
|
for (let i = 0; i < basePrices.length; ++i) {
|
||||||
|
itemPrices[i] = (basePrices[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
multValue = document.getElementById(id).value;
|
||||||
|
}
|
||||||
|
// Determine index to update
|
||||||
|
for (let i = 0; i < ids.length; ++i) {
|
||||||
|
if (id == ids[i]) {
|
||||||
|
var idIndex = i;
|
||||||
|
multipliers[i] = multValue;
|
||||||
|
console.log("idIndex:", idIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Set itemPrices;
|
||||||
|
//itemPrices = []; //Clear array
|
||||||
|
for (let i = 0; i < basePrices.length; ++i) {
|
||||||
|
if (idIndex == i) {
|
||||||
|
itemPrices[i] = (basePrices[i] * multValue);
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tableBuilder();
|
||||||
|
console.log(id + ": ", itemPrices[idIndex]);
|
||||||
|
}
|
||||||
|
function tableBuilder() {
|
||||||
|
let itemNames = ["Notebook", "Pen", "Mechanical Pencil", "Lead refil pack", "Laptop case", "Cellphone case", "3-ring binder", "3-hole paper refil"];
|
||||||
|
let tableString = "";
|
||||||
|
tableString = "<table>" + "<tr>" + " <th>Item Name</th>" + " <th>Quantity</th>" + " <th>Price</th>" + " </tr>";
|
||||||
|
|
||||||
|
for (let i = 0; i < itemNames.length; ++i) {
|
||||||
|
tableString += "<tr>";
|
||||||
|
tableString += "<td>" + itemNames[i] + "</td>";
|
||||||
|
tableString += "<td>" + "<input type='number' min='0'" + "id='" + ids[i] + "' onChange='updateMultiplier(this.id);'" + "value='" + multipliers[i] + "' >" + "</td>";
|
||||||
|
tableString += "<td>" + formatter.format(itemPrices[i]) + "</td>";
|
||||||
|
tableString += "</tr>";
|
||||||
|
}
|
||||||
|
tableString += "</table>";
|
||||||
|
tableString += "<p> Total: " + formatter.format(getTotal()) + "</p>";
|
||||||
|
document.getElementById("tableDiv").innerHTML = tableString;
|
||||||
|
}
|
||||||
|
updateMultiplier();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<!--
|
||||||
|
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
Click nbfs://nbhost/SystemFileSystem/Templates/ClientSide/html.html to edit this template
|
||||||
|
-->
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Problem 5</title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<style>
|
||||||
|
table, th, td {
|
||||||
|
border: 1px solid;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<div id="tableDiv"></div>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
function getAverage(gradeArray, testSet, numTests) {
|
||||||
|
let gradeAverage = 0;
|
||||||
|
for (let i = 0; i < gradeArray[testSet].length; ++i) {
|
||||||
|
gradeAverage += parseFloat(gradeArray[testSet][i]);
|
||||||
|
}
|
||||||
|
console.log(gradeAverage);
|
||||||
|
gradeAverage = gradeAverage / numTests;
|
||||||
|
console.log("Grade average: " + gradeAverage);
|
||||||
|
return gradeAverage;
|
||||||
|
}
|
||||||
|
// Get user input
|
||||||
|
var studentNameArray = [];
|
||||||
|
var gradeArray = [];
|
||||||
|
var numOfStudents = 0, numTests = 0;
|
||||||
|
numOfStudents = prompt("Enter the number of students to enter into the table.")
|
||||||
|
numTests = prompt("Enter the number of tests administered: ");
|
||||||
|
for (let i = 0, j = numOfStudents; i < numOfStudents; ++i, --j) {
|
||||||
|
var nameInput = prompt("Enter a student name. (" + j + " left).");
|
||||||
|
studentNameArray.push(nameInput);
|
||||||
|
let testArray = [];
|
||||||
|
for (let k = 0; k < numTests; ++k) {
|
||||||
|
let grade = prompt("Enter " + nameInput + "'s grade for test " + (k + 1) + ": ");
|
||||||
|
testArray.push(grade);
|
||||||
|
}
|
||||||
|
gradeArray.push(testArray);
|
||||||
|
}
|
||||||
|
console.log(studentNameArray, gradeArray);
|
||||||
|
let tableString = "<table>" + "<tr>" + " <th>Student Name</th>";
|
||||||
|
for (let i = 0; i < numTests; ++i) {
|
||||||
|
tableString += "<th>";
|
||||||
|
tableString += "Test " + (i + 1);
|
||||||
|
tableString += "</th>";
|
||||||
|
}
|
||||||
|
|
||||||
|
tableString += " <th>Grade Average</th>" + " </tr>";
|
||||||
|
for (let i = 0; i < studentNameArray.length; ++i) {
|
||||||
|
tableString += "<tr>" + "<td>" + studentNameArray[i] + "</td>";
|
||||||
|
for (let j = 0; j < numTests; ++j) {
|
||||||
|
tableString += "<td>" + gradeArray[i][j] + "</td>";
|
||||||
|
}
|
||||||
|
tableString += "<td>" + getAverage(gradeArray, i, numTests) + "</td>";
|
||||||
|
tableString += "</tr>";
|
||||||
|
}
|
||||||
|
document.getElementById("tableDiv").innerHTML = tableString;
|
||||||
|
</script>
|
||||||
|
</html>
|
@ -0,0 +1,66 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<!--
|
||||||
|
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
Click nbfs://nbhost/SystemFileSystem/Templates/ClientSide/html.html to edit this template
|
||||||
|
-->
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Problem 6</title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<style>
|
||||||
|
table, th, td {
|
||||||
|
border: 1px solid;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<div id="tableDiv"></div>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
// Get user input
|
||||||
|
var array = [];
|
||||||
|
var numOfStudents = 0, numTests = 0;
|
||||||
|
numOfStudents = prompt("Enter the number of students to enter into the table.")
|
||||||
|
numTests = prompt("Enter the number of tests administered: ");
|
||||||
|
for (let i = 0, j = numOfStudents; i < numOfStudents; ++i, --j) {
|
||||||
|
var nameInput = prompt("Enter a student name. (" + j + " left).");
|
||||||
|
array[i] = [nameInput, undefined];
|
||||||
|
let testArray = [];
|
||||||
|
for (let k = 0; k < numTests; ++k) {
|
||||||
|
let grade = prompt("Enter " + nameInput + "'s grade for test " + (k + 1) + ": ");
|
||||||
|
testArray.push(grade);
|
||||||
|
}
|
||||||
|
array[i] = [array[i][0], testArray];
|
||||||
|
}
|
||||||
|
console.log(array);
|
||||||
|
let tableString = "<table>" + "<tr>" + " <th>Student Name</th>";
|
||||||
|
for (let i = 0; i < numTests; ++i) {
|
||||||
|
tableString += "<th>";
|
||||||
|
tableString += "Test " + (i + 1);
|
||||||
|
tableString += "</th>";
|
||||||
|
}
|
||||||
|
|
||||||
|
tableString += " <th>Grade Average</th>" + " </tr>";
|
||||||
|
for (let i = 0; i < array.length; ++i) {
|
||||||
|
tableString += "<tr>" + "<td>" + array[i][0] + "</td>";
|
||||||
|
for (let j = 0; j < numTests; ++j) {
|
||||||
|
tableString += "<td>" + array[i][1][j] + "</td>";
|
||||||
|
}
|
||||||
|
tableString += "<td>" + getAverage(array, i, numTests) + "</td>";
|
||||||
|
tableString += "</tr>";
|
||||||
|
}
|
||||||
|
document.getElementById("tableDiv").innerHTML = tableString;
|
||||||
|
function getAverage(array, testSet, numTests) {
|
||||||
|
console.log(array)
|
||||||
|
let gradeAverage = 0;
|
||||||
|
for (let i = 0; i < numTests; ++i) { //gradeArray[testSet].length
|
||||||
|
gradeAverage += parseFloat(array[testSet][1][i]);
|
||||||
|
}
|
||||||
|
console.log(gradeAverage);
|
||||||
|
gradeAverage = gradeAverage / numTests;
|
||||||
|
console.log("Grade average: " + gradeAverage);
|
||||||
|
return gradeAverage;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</html>
|
@ -0,0 +1,56 @@
|
|||||||
|
<!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>
|
||||||
|
<style>
|
||||||
|
table, th, td {
|
||||||
|
border: 1px solid;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<div id="tableDiv"></div>
|
||||||
|
<div id="magicResult"></div>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
// Create 2D array.
|
||||||
|
let magic = [];
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
magic.push([0, 0, 0, 0]);
|
||||||
|
}
|
||||||
|
console.log(magic);
|
||||||
|
//Get input
|
||||||
|
for (let x = 0; x < magic.length; ++x) {
|
||||||
|
for (let y = 0; y < magic[x].length; ++y) {
|
||||||
|
magic[x][y] = prompt("Enter value for " + (x + 1) + ", " + (y + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(magic);
|
||||||
|
// Calculate diagonals
|
||||||
|
var diagonal1 = magic[0][0] + magic[1][1] + magic[2][2] + magic[3][3];
|
||||||
|
var diagonal2 = magic[0][3] + magic[1][2] + magic[2][1] + magic[3][0];
|
||||||
|
let tableString = "<table>";
|
||||||
|
for (let x = 0; x < magic.length; ++x) {
|
||||||
|
tableString += "<tr>";
|
||||||
|
for (let y = 0; y < magic[x].length; ++y) {
|
||||||
|
tableString += "<td>" + magic[x][y] + "</td>";
|
||||||
|
}
|
||||||
|
tableString += "</tr>";
|
||||||
|
}
|
||||||
|
tableString += "</table>";
|
||||||
|
let magicResult = "";
|
||||||
|
if (diagonal1 == diagonal2) {
|
||||||
|
magicResult = "This is a magic square.";
|
||||||
|
} else {
|
||||||
|
magicResult = "This is not a magic square."
|
||||||
|
}
|
||||||
|
document.getElementById("tableDiv").innerHTML = tableString;
|
||||||
|
document.getElementById("magicResult").innerHTML = "<p>" + magicResult + "</p>";
|
||||||
|
</script>
|
||||||
|
</html>
|
@ -1,15 +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>TODO supply a title</title>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div>TODO write content</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
BIN
ZIPs/JavaScript/MP13_CalebFontenot.zip
Normal file
BIN
ZIPs/JavaScript/MP13_CalebFontenot.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user