Device Sync

This commit is contained in:
2025-12-18 22:10:59 -05:00
parent 364f6756c2
commit 0b903ae50d
36 changed files with 3151 additions and 3151 deletions

View File

@@ -1,35 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>Lab 2</title>
</head>
<body>
<h1>Lab 2</h1>
<script>
/*
* Name: Levi McLean
* Project: Lab 1
* Submission date: September 18th, 2025
*/
var studentName; //unassigned variable
do {
studentName = prompt("Enter the student's name: "); //prompt for name, assign variable with value
if (studentName === null || studentName.trim() === "") {
alert("Please enter a student name");
}
} while (studentName === null || studentName.trim() === "");
alert("Thank you for your entry!"); //Pop up message alert
sessionStorage.setItem("Student Name", studentName);
const welcomeText = "Welcome to INFO-1272 Fall 2025 "; //set const welcomeText
const nameText = `You are ${sessionStorage.getItem("Student Name")}`;
document.write(welcomeText); //write const welcomeText
document.write("<br>");
document.write(nameText);
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<title>Lab 2</title>
</head>
<body>
<h1>Lab 2</h1>
<script>
/*
* Name: Levi McLean
* Project: Lab 1
* Submission date: September 18th, 2025
*/
var studentName; //unassigned variable
do {
studentName = prompt("Enter the student's name: "); //prompt for name, assign variable with value
if (studentName === null || studentName.trim() === "") {
alert("Please enter a student name");
}
} while (studentName === null || studentName.trim() === "");
alert("Thank you for your entry!"); //Pop up message alert
sessionStorage.setItem("Student Name", studentName);
const welcomeText = "Welcome to INFO-1272 Fall 2025 "; //set const welcomeText
const nameText = `You are ${sessionStorage.getItem("Student Name")}`;
document.write(welcomeText); //write const welcomeText
document.write("<br>");
document.write(nameText);
</script>
</body>
</html>

View File

@@ -1,81 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<title>Lab 2</title>
</head>
<body>
<h1>Theme Park Tickets</h1>
<script>
// Constant values
const CHILD_TICKET_PRICE = 9.99;
const ADULT_TICKET_PRICE = 19.99;
const SENIOR_TICKET_PRICE = 14.99;
const HST_TAX = 0.13;
// Unassigned for now, assign later
var ticketType;
var ticketPrice;
var userAge;
var firstName;
var lastName;
var email;
var phone;
var tax;
var total;
var freeRides;
// Ask for user details
firstName = prompt("First Name:");
lastName = prompt("Last Name:");
email = prompt("Email:");
phone = prompt("Phone:");
userAge = prompt("Enter your age:");
// Determine ticket price
if (userAge < 12) {
ticketPrice = CHILD_TICKET_PRICE;
ticketType = "Child";
} else if (userAge <= 59) {
ticketPrice = ADULT_TICKET_PRICE;
ticketType = "Adult";
} else {
ticketPrice = SENIOR_TICKET_PRICE;
ticketType = "Senior";
}
// Determine free ride coupons
if (ticketType === "Child") {
freeRides = 0;
} else if (ticketType === "Adult") {
freeRides = 2;
} else {
freeRides = 1;
}
// Caluclate tax and total
tax = ticketPrice * HST_TAX;
total = ticketPrice + tax;
// Display to console
console.log("==========================================");
console.log(" Theme Park Ticket Receipt ");
console.log("==========================================");
console.log("Customer Name: ", firstName, lastName);
console.log("Email: ", email);
console.log("Phone: ", phone);
console.log("------------------------------------------");
console.log("Ticket Type: ", ticketType);
console.log("Base Price: $", ticketPrice.toFixed(2));
console.log("Tax (13%): $", tax.toFixed(2));
console.log("TOTAL: $", total.toFixed(2));
console.log("------------------------------------------");
console.log("Free Ride Coupons Earned: ", freeRides);
console.log("==========================================");
console.log(" Have a fun and safe day at the park! ");
console.log("==========================================");
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<title>Lab 2</title>
</head>
<body>
<h1>Theme Park Tickets</h1>
<script>
// Constant values
const CHILD_TICKET_PRICE = 9.99;
const ADULT_TICKET_PRICE = 19.99;
const SENIOR_TICKET_PRICE = 14.99;
const HST_TAX = 0.13;
// Unassigned for now, assign later
var ticketType;
var ticketPrice;
var userAge;
var firstName;
var lastName;
var email;
var phone;
var tax;
var total;
var freeRides;
// Ask for user details
firstName = prompt("First Name:");
lastName = prompt("Last Name:");
email = prompt("Email:");
phone = prompt("Phone:");
userAge = prompt("Enter your age:");
// Determine ticket price
if (userAge < 12) {
ticketPrice = CHILD_TICKET_PRICE;
ticketType = "Child";
} else if (userAge <= 59) {
ticketPrice = ADULT_TICKET_PRICE;
ticketType = "Adult";
} else {
ticketPrice = SENIOR_TICKET_PRICE;
ticketType = "Senior";
}
// Determine free ride coupons
if (ticketType === "Child") {
freeRides = 0;
} else if (ticketType === "Adult") {
freeRides = 2;
} else {
freeRides = 1;
}
// Caluclate tax and total
tax = ticketPrice * HST_TAX;
total = ticketPrice + tax;
// Display to console
console.log("==========================================");
console.log(" Theme Park Ticket Receipt ");
console.log("==========================================");
console.log("Customer Name: ", firstName, lastName);
console.log("Email: ", email);
console.log("Phone: ", phone);
console.log("------------------------------------------");
console.log("Ticket Type: ", ticketType);
console.log("Base Price: $", ticketPrice.toFixed(2));
console.log("Tax (13%): $", tax.toFixed(2));
console.log("TOTAL: $", total.toFixed(2));
console.log("------------------------------------------");
console.log("Free Ride Coupons Earned: ", freeRides);
console.log("==========================================");
console.log(" Have a fun and safe day at the park! ");
console.log("==========================================");
</script>
</body>
</html>

View File

@@ -1,61 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<title>Lab 3</title>
<meta charset="UTF-8">
</head>
<body>
<h1>Lab 3</h1>
<script>
/*
* I have decided to declare my fortune messages in order of
* most-to-least positive
*/
var fortune1 = "You will have a great day";
var fortune2 = "Success if around the corner";
var fortune3 = "Happiness comes from within";
var fortune4 = "Today will be okay";
var fortune5 = "Keep an eye on the details";
var fortune6 = "Patience will be tested";
var fortune7 = "You will step on LEGO soon";
var fortune8 = "Beware of pigeons, they have attitude";
var fortune9 = "Your WIFI will mysteriously stop working";
// Prompt user for numCookies
var numCookies = window.prompt("How many cookies do you want to open?");
// Loop starting at 1, stoping at numCookies
for (var i = 1; i <=numCookies; i++) {
// Generate random number from 1 - 9 inclusive
var randNum = Math.floor(Math.random() * 9) + 1;
// Assign messge and cateogry to blank for now
var message = ""
var category = ""
// Determine message and category from randNum
if (randNum <= 3) {
if (randNum === 1) message = fortune1;
else if (randNum === 2) message = fortune2;
else message = fortune3;
category = "Positive"; // Positive if 1-3
} else if (randNum <= 6) {
if (randNum === 4) message = fortune4;
else if (randNum === 5) message = fortune5;
else message = fortune6;
category = "Neutral"; // Neutral if 4-6
} else {
if (randNum === 7) message = fortune7;
else if (randNum === 8) message = fortune8;
else message = fortune9;
category = "Funny" // Funny if 7-9
}
// Display fortune cookie details
console.log("Cookie #" + i + "\nMessage: " + message + "\nCategory: " + category);
}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<title>Lab 3</title>
<meta charset="UTF-8">
</head>
<body>
<h1>Lab 3</h1>
<script>
/*
* I have decided to declare my fortune messages in order of
* most-to-least positive
*/
var fortune1 = "You will have a great day";
var fortune2 = "Success if around the corner";
var fortune3 = "Happiness comes from within";
var fortune4 = "Today will be okay";
var fortune5 = "Keep an eye on the details";
var fortune6 = "Patience will be tested";
var fortune7 = "You will step on LEGO soon";
var fortune8 = "Beware of pigeons, they have attitude";
var fortune9 = "Your WIFI will mysteriously stop working";
// Prompt user for numCookies
var numCookies = window.prompt("How many cookies do you want to open?");
// Loop starting at 1, stoping at numCookies
for (var i = 1; i <=numCookies; i++) {
// Generate random number from 1 - 9 inclusive
var randNum = Math.floor(Math.random() * 9) + 1;
// Assign messge and cateogry to blank for now
var message = ""
var category = ""
// Determine message and category from randNum
if (randNum <= 3) {
if (randNum === 1) message = fortune1;
else if (randNum === 2) message = fortune2;
else message = fortune3;
category = "Positive"; // Positive if 1-3
} else if (randNum <= 6) {
if (randNum === 4) message = fortune4;
else if (randNum === 5) message = fortune5;
else message = fortune6;
category = "Neutral"; // Neutral if 4-6
} else {
if (randNum === 7) message = fortune7;
else if (randNum === 8) message = fortune8;
else message = fortune9;
category = "Funny" // Funny if 7-9
}
// Display fortune cookie details
console.log("Cookie #" + i + "\nMessage: " + message + "\nCategory: " + category);
}
</script>
</body>
</html>

View File

@@ -1,93 +1,93 @@
<!DOCTYPE html>
<html>
<head>
<title>Lab 5</title>
<meta charset="utf-8" lang="en">
</head>
<body>
<h1>Lab 5</h1>
<script>
// Get number of students in class
var numStudents = parseInt(window.prompt("How many students are in the class?"));
var studentNames = [];
var studentGrades = [];
// Run grade analytics once so theres something to display
gradeAnalyzer();
calculateAverage(studentGrades);
findMinMax(studentGrades);
// Ask user if they want to review the results
do {
displayResults();
var viewAgain = window.confirm("Would you like to view the results again?");
} while (viewAgain);
// Thank user and end loop
alert("Thank you for using the Grade Analyzer!");
// Function Definitions from here on
// Gets names, grades and inserts into respective arrays
function gradeAnalyzer() {
for (var i = 0; i <= numStudents - 1; i++) {
var studentName = window.prompt("Enter students name:");
var studentGrade = parseFloat(window.prompt("Enter student grade:"));
if (studentGrade > 0 && studentGrade <= 100) {
studentNames.push(studentName);
studentGrades.push(studentGrade);
} else {
alert("Invalid grade entered, skipping entry");
}
console.log("Student " + (i + 1) + ": " + studentName + " - Grade: " + studentGrade);
}
}
// Calculates the average of a given array
function calculateAverage(arr) {
var totalGrades = 0;
for (var i = 0; i < arr.length; i++) {
totalGrades += arr[i];
}
var average = totalGrades / arr.length;
console.log("Class average: " + average.toFixed(2));
}
// Finds the minimum and maximum value of an array by looping through it
function findMinMax(arr) {
if (arr.length === 0) {
return
}
var min = arr[0];
var max = arr[0];
for (var i = 1; i < arr.length; i++) {
var grade = arr[i];
if (grade < min) {
min = grade;
}
if (grade > max) {
max = grade;
}
}
console.log("Min: " + min + " Max: " + max);
}
// Helper function to display results cleanly
function displayResults() {
console.clear();
console.log("Student List:");
for (var i = 0; i < studentNames.length; i++) {
console.log("Student " + i + ": " + studentNames[i] + " Grade: " + studentGrades[i]);
}
calculateAverage(studentGrades);
findMinMax(studentGrades);
}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<title>Lab 5</title>
<meta charset="utf-8" lang="en">
</head>
<body>
<h1>Lab 5</h1>
<script>
// Get number of students in class
var numStudents = parseInt(window.prompt("How many students are in the class?"));
var studentNames = [];
var studentGrades = [];
// Run grade analytics once so theres something to display
gradeAnalyzer();
calculateAverage(studentGrades);
findMinMax(studentGrades);
// Ask user if they want to review the results
do {
displayResults();
var viewAgain = window.confirm("Would you like to view the results again?");
} while (viewAgain);
// Thank user and end loop
alert("Thank you for using the Grade Analyzer!");
// Function Definitions from here on
// Gets names, grades and inserts into respective arrays
function gradeAnalyzer() {
for (var i = 0; i <= numStudents - 1; i++) {
var studentName = window.prompt("Enter students name:");
var studentGrade = parseFloat(window.prompt("Enter student grade:"));
if (studentGrade > 0 && studentGrade <= 100) {
studentNames.push(studentName);
studentGrades.push(studentGrade);
} else {
alert("Invalid grade entered, skipping entry");
}
console.log("Student " + (i + 1) + ": " + studentName + " - Grade: " + studentGrade);
}
}
// Calculates the average of a given array
function calculateAverage(arr) {
var totalGrades = 0;
for (var i = 0; i < arr.length; i++) {
totalGrades += arr[i];
}
var average = totalGrades / arr.length;
console.log("Class average: " + average.toFixed(2));
}
// Finds the minimum and maximum value of an array by looping through it
function findMinMax(arr) {
if (arr.length === 0) {
return
}
var min = arr[0];
var max = arr[0];
for (var i = 1; i < arr.length; i++) {
var grade = arr[i];
if (grade < min) {
min = grade;
}
if (grade > max) {
max = grade;
}
}
console.log("Min: " + min + " Max: " + max);
}
// Helper function to display results cleanly
function displayResults() {
console.clear();
console.log("Student List:");
for (var i = 0; i < studentNames.length; i++) {
console.log("Student " + i + ": " + studentNames[i] + " Grade: " + studentGrades[i]);
}
calculateAverage(studentGrades);
findMinMax(studentGrades);
}
</script>
</body>
</html>

View File

@@ -1,130 +1,130 @@
<!DOCTYPE html>
<html>
<head>
<title>Levi McLean Midterm Part B</title>
<meta charset="utf-8" lang="en-us">
</head>
<body>
<h1>Levi McLean Midterm Part B</h1>
<script>
const TAX_RATE = 0.13;
const DISCOUNT_RATE = 0.1;
var item1 = {
name: "apple",
price: 1.1,
qty: 4
};
var item2 = {
name: "banana",
price: 0.59,
qty: 2
};
var item3 = {
name: "pear",
price: 1.25,
qty: 6
};
var item4 = {
name: "grapes",
price: 2.25,
qty: 8
};
var item5 = {
name: "kiwi",
price: 3,
qty: 1
};
var cart = [item1, item2, item3, item4, item5];
function searchItem() {
var itemName = window.prompt("Enter an item name: ").toLowerCase();
var foundItem;
if (itemName == null) {
window.alert("Item name cannot be null.");
}
for (var i=0; i < cart.length; i++) {
if (cart[i].name === itemName) {
window.alert("Item(s) found.");
foundItem = cart[i];
return foundItem;
}
}
window.alert("Item(s) not found.");
return undefined;
}
function updateItemQuantity() {
var updateItem = window.prompt("Enter item name to update: ").toLowerCase();
if (updateItem == null) {
window.alert("Invalid item name.");
}
for (var i=0; i < cart.length; i++) {
if (cart[i].name === updateItem) {
var updateQty = parseInt(window.prompt("How many items do we add? "), 10);
cart[i].qty += updateQty;
console.log(cart);
return updateItem;
}
}
window.alert("Item does not exist in cart.");
return undefined;
}
function clearCart() {
for (var i = 0; i < cart.length; i++) {
cart[i].name = "";
cart[i].qty = 0;
}
console.log(cart);
window.alert("Cart has been cleared!");
}
function calulateFinalPriceWithDiscount() {
var subtotal = 0;
for (var i = 0; i < cart.length; i++) {
subtotal += cart[i].price * cart[i].qty;
}
var tax = subtotal * TAX_RATE;
var discount = subtotal * DISCOUNT_RATE;
var total = subtotal - discount + tax;
window.alert(
"Subtotal: $" + subtotal.toFixed(2) + "\n" +
"Tax: $" + tax.toFixed(2) + "\n" +
"Discount: $" + discount.toFixed(2) + "\n" +
"Total: $" + total.toFixed(2)
);
}
var notDone = true;
while(notDone === true) {
var userChoice = window.prompt("Please make a selection (s)earch, (u)pdate, (c)lear, (d)iscount: ").toLowerCase();
if (userChoice === "s") {
searchItem();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "u") {
updateItemQuantity();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "c") {
clearCart();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "d") {
calulateFinalPriceWithDiscount();
notDone = window.confirm("Do you wish to continue?");
} else {
window.alert("Invalid selection, try again.");
}
}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<title>Levi McLean Midterm Part B</title>
<meta charset="utf-8" lang="en-us">
</head>
<body>
<h1>Levi McLean Midterm Part B</h1>
<script>
const TAX_RATE = 0.13;
const DISCOUNT_RATE = 0.1;
var item1 = {
name: "apple",
price: 1.1,
qty: 4
};
var item2 = {
name: "banana",
price: 0.59,
qty: 2
};
var item3 = {
name: "pear",
price: 1.25,
qty: 6
};
var item4 = {
name: "grapes",
price: 2.25,
qty: 8
};
var item5 = {
name: "kiwi",
price: 3,
qty: 1
};
var cart = [item1, item2, item3, item4, item5];
function searchItem() {
var itemName = window.prompt("Enter an item name: ").toLowerCase();
var foundItem;
if (itemName == null) {
window.alert("Item name cannot be null.");
}
for (var i=0; i < cart.length; i++) {
if (cart[i].name === itemName) {
window.alert("Item(s) found.");
foundItem = cart[i];
return foundItem;
}
}
window.alert("Item(s) not found.");
return undefined;
}
function updateItemQuantity() {
var updateItem = window.prompt("Enter item name to update: ").toLowerCase();
if (updateItem == null) {
window.alert("Invalid item name.");
}
for (var i=0; i < cart.length; i++) {
if (cart[i].name === updateItem) {
var updateQty = parseInt(window.prompt("How many items do we add? "), 10);
cart[i].qty += updateQty;
console.log(cart);
return updateItem;
}
}
window.alert("Item does not exist in cart.");
return undefined;
}
function clearCart() {
for (var i = 0; i < cart.length; i++) {
cart[i].name = "";
cart[i].qty = 0;
}
console.log(cart);
window.alert("Cart has been cleared!");
}
function calulateFinalPriceWithDiscount() {
var subtotal = 0;
for (var i = 0; i < cart.length; i++) {
subtotal += cart[i].price * cart[i].qty;
}
var tax = subtotal * TAX_RATE;
var discount = subtotal * DISCOUNT_RATE;
var total = subtotal - discount + tax;
window.alert(
"Subtotal: $" + subtotal.toFixed(2) + "\n" +
"Tax: $" + tax.toFixed(2) + "\n" +
"Discount: $" + discount.toFixed(2) + "\n" +
"Total: $" + total.toFixed(2)
);
}
var notDone = true;
while(notDone === true) {
var userChoice = window.prompt("Please make a selection (s)earch, (u)pdate, (c)lear, (d)iscount: ").toLowerCase();
if (userChoice === "s") {
searchItem();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "u") {
updateItemQuantity();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "c") {
clearCart();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "d") {
calulateFinalPriceWithDiscount();
notDone = window.confirm("Do you wish to continue?");
} else {
window.alert("Invalid selection, try again.");
}
}
</script>
</body>
</html>

View File

@@ -1,138 +1,138 @@
<!DOCTYPE html>
<html>
<head>
<title>Levi McLean Midterm Part B</title>
<meta charset="utf-8" lang="en-us">
</head>
<body>
<h1>Levi McLean Midterm Part B</h1>
<script>
const TAX_RATE = 0.13;
const DISCOUNT_RATE = 0.1;
var item1 = {
name: "apple",
price: 1.1,
qty: 4
};
var item2 = {
name: "banana",
price: 0.59,
qty: 2
};
var item3 = {
name: "pear",
price: 1.25,
qty: 6
};
var item4 = {
name: "grapes",
price: 2.25,
qty: 8
};
var item5 = {
name: "kiwi",
price: 3,
qty: 1
};
var cart = [item1, item2, item3, item4, item5];
function searchItem() {
var itemName = window.prompt("Enter an item name: ").toLowerCase();
var foundItem;
if (itemName == null) {
window.alert("Item name cannot be null.");
}
for (var i=0; i <= cart.length; i++) {
if (cart[i].name === itemName) {
window.alert("Item(s) found.");
foundItem = cart[i];
return foundItem;
}
}
window.alert("Item(s) not found.");
return undefined;
}
function updateItemQuantity() {
var updateItem = window.prompt("Enter item name to update: ").toLowerCase();
if (updateItem == null) {
window.alert("Invalid item name.");
}
for (var i=0; i <= cart.length; i++) {
if (cart[i].name === updateItem) {
var updateQty = parseInt(window.prompt("How many items do we add? "), 10);
cart[i].qty += updateQty;
console.log(cart);
return updateItem;
}
window.alert("Item does not exist in cart.");
return undefined;
}
}
function clearCart() {
cart[0].name = "";
cart[0].qty = 0;
cart[1].name = "";
cart[1].qty = 0;
cart[2].name = "";
cart[2].qty = 0;
cart[3].name = "";
cart[3].qty = 0;
cart[4].name = "";
cart[4].qty = 0;
console.log(cart);
window.alert("Cart has been cleared!");
}
function calulateFinalPriceWithDiscount() {
var subtotal = 0;
var tax = 0;
var total = 0;
// for (var i = 0; i <= cart.length; i++) {
// subtotal += cart[i].price;
// }
subtotal += cart[0].price;
subtotal += cart[1].price;
subtotal += cart[2].price;
subtotal += cart[3].price;
subtotal += cart[4].price;
tax = subtotal * TAX_RATE;
discount = subtotal * DISCOUNT_RATE;
total = subtotal - discount + tax;
window.alert("Subtotal: $" + subtotal + " Tax: $" + tax + " Total: $" + total);
}
var notDone = true;
while(notDone === true) {
var userChoice = window.prompt("Please make a selection (s)earch, (u)pdate, (c)lear, (d)iscount: ").toLowerCase();
if (userChoice === "s") {
searchItem();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "u") {
updateItemQuantity();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "c") {
clearCart();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "d") {
calulateFinalPriceWithDiscount();
notDone = window.confirm("Do you wish to continue?");
} else {
window.alert("Invalid selection, try again.");
}
}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<title>Levi McLean Midterm Part B</title>
<meta charset="utf-8" lang="en-us">
</head>
<body>
<h1>Levi McLean Midterm Part B</h1>
<script>
const TAX_RATE = 0.13;
const DISCOUNT_RATE = 0.1;
var item1 = {
name: "apple",
price: 1.1,
qty: 4
};
var item2 = {
name: "banana",
price: 0.59,
qty: 2
};
var item3 = {
name: "pear",
price: 1.25,
qty: 6
};
var item4 = {
name: "grapes",
price: 2.25,
qty: 8
};
var item5 = {
name: "kiwi",
price: 3,
qty: 1
};
var cart = [item1, item2, item3, item4, item5];
function searchItem() {
var itemName = window.prompt("Enter an item name: ").toLowerCase();
var foundItem;
if (itemName == null) {
window.alert("Item name cannot be null.");
}
for (var i=0; i <= cart.length; i++) {
if (cart[i].name === itemName) {
window.alert("Item(s) found.");
foundItem = cart[i];
return foundItem;
}
}
window.alert("Item(s) not found.");
return undefined;
}
function updateItemQuantity() {
var updateItem = window.prompt("Enter item name to update: ").toLowerCase();
if (updateItem == null) {
window.alert("Invalid item name.");
}
for (var i=0; i <= cart.length; i++) {
if (cart[i].name === updateItem) {
var updateQty = parseInt(window.prompt("How many items do we add? "), 10);
cart[i].qty += updateQty;
console.log(cart);
return updateItem;
}
window.alert("Item does not exist in cart.");
return undefined;
}
}
function clearCart() {
cart[0].name = "";
cart[0].qty = 0;
cart[1].name = "";
cart[1].qty = 0;
cart[2].name = "";
cart[2].qty = 0;
cart[3].name = "";
cart[3].qty = 0;
cart[4].name = "";
cart[4].qty = 0;
console.log(cart);
window.alert("Cart has been cleared!");
}
function calulateFinalPriceWithDiscount() {
var subtotal = 0;
var tax = 0;
var total = 0;
// for (var i = 0; i <= cart.length; i++) {
// subtotal += cart[i].price;
// }
subtotal += cart[0].price;
subtotal += cart[1].price;
subtotal += cart[2].price;
subtotal += cart[3].price;
subtotal += cart[4].price;
tax = subtotal * TAX_RATE;
discount = subtotal * DISCOUNT_RATE;
total = subtotal - discount + tax;
window.alert("Subtotal: $" + subtotal + " Tax: $" + tax + " Total: $" + total);
}
var notDone = true;
while(notDone === true) {
var userChoice = window.prompt("Please make a selection (s)earch, (u)pdate, (c)lear, (d)iscount: ").toLowerCase();
if (userChoice === "s") {
searchItem();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "u") {
updateItemQuantity();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "c") {
clearCart();
notDone = window.confirm("Do you wish to continue?");
} else if (userChoice === "d") {
calulateFinalPriceWithDiscount();
notDone = window.confirm("Do you wish to continue?");
} else {
window.alert("Invalid selection, try again.");
}
}
</script>
</body>
</html>