changes to lab2 file

This commit is contained in:
soyed 2021-02-10 20:22:59 -05:00
parent 5c99005ad2
commit 4917604c81
15 changed files with 205 additions and 81 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
images/bread.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 KiB

BIN
images/broccoli.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
images/carrot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

BIN
images/cereal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 KiB

BIN
images/cheese.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
images/chicken.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
images/honey.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
images/onion.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 KiB

BIN
images/salmon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

BIN
images/white-fish.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

View file

@ -1,68 +1,104 @@
<!DOCTYPE html>
<html>
<head>
<! This style sheet is taken from https://www.w3schools.com/howto/howto_js_tabs.asp>
<link href="styles/style.css" rel="stylesheet" type="text/css">
</head>
<head>
<!--This style sheet is taken from https://www.w3schools.com/howto/howto_js_tabs.asp -->
<link href="styles/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<body>
<div class="company-name">
<h1>Sam's Mart</h1>
<img class="cart-img" src="images/logo.png" alt="mart-img">
</div>
<div>
<h1> Sam's Mart </h1>
<a href="https://samsmartinc.com/">
<img src="images/logo.png" alt="Facebook" class = "logo">
</a>
<!-- Tab links, each one with an onclick event associated with it -->
<div class="tab">
<button class="tablinks" onclick="openInfo(event, 'Client')">
Client
</button>
<button class="tablinks" onclick="openInfo(event, 'Products')">
Products
</button>
<button class="tablinks" onclick="openInfo(event, 'Cart')">Cart</button>
</div>
</div>
<!-- Tab content -->
<div id="Client" class="tabcontent">
<h3>Client Information</h3>
<p>Tell us a bit about you.</p>
<i><strong>Choose a Category:</strong></i>
<select
id="dietSelect"
name="dietSelect"
class="sumo"
onchange="populateListProductChoices(this.id, 'displayProduct')"
>
<option value=""></option>
<!-- Tab links, each one with an onclick event associated with it -->
<div class="tab">
<button class="tablinks" onclick="openInfo(event, 'Client')">Client</button>
<button class="tablinks" onclick="openInfo(event, 'Products')">Products</button>
<button class="tablinks" onclick="openInfo(event, 'Cart')">Cart</button>
</div>
<option value="Vegetarian">Vegetarian</option>
<option value="GlutenFree">Gluten Free</option>
<option value="VegetarianANDGluten-Free">
Vegetarian and Gluten-Free
</option>
<option value="Organic">Organic</option>
<option value="Non-organic">Non-Organic</option>
<option value="None">None</option>
</select>
<br>
<i><strong>Choose a Characteristic:</strong></i>
<select class="sumo" name="characterSelect">
<option value=""></option>
<option value="Diabetic">Diabetic</option>
<option value="LactoseIntolerant">Lactose intolerant</option>
</select>
<!-- Tab content -->
<div id="Client" class="tabcontent">
<h3>Client Information</h3>
<p>Tell us a bit about you.</p>
Choose a Category:
<select id="dietSelect" name="dietSelect" onchange="populateListProductChoices(this.id, 'displayProduct')">
<option value=""></option>
<div class="footer">
<p class="copyright">
Website created by Ruchira, Sam, Batuhan, and Kene
</p>
</div>
<option value="Vegetarian">Vegetarian</option>
<option value="GlutenFree">Gluten Free</option>
<option value="VegetarianANDGluten-Free">Vegetarian and Gluten-Free</option>
<option value="Organic">Organic</option>
<option value="Non-organic">Non-Organic</option>
<option value="None">None</option>
</div>
</select>
</div>
<div id="Products" class="tabcontent">
<h3>Your targeted products</h3>
<p>We preselected products based on your restrictions.</p>
<i><strong>Choose items to buy:</strong></i>
<div id="displayProduct"></div>
<button
id="addCart"
type="button"
class="block"
onclick="selectedItems()"
>
Add selected items to cart.
</button>
<div class="footer">
<p class="copyright">
Website created by Ruchira, Sam, Batuhan, and Kene
</p>
</div>
<div id="Products" class="tabcontent">
<h3>Your targeted products</h3>
<p>We preselected products based on your restrictions.</p>
Choose items to buy:
<div id="displayProduct"></div>
<button id="addCart" type="button" class="block" onclick="selectedItems()">
Add selected items to cart.
</button>
</div>
<div id="Cart" class="tabcontent">
<h3>Cart</h3>
<p>Here is your cart.</p>
<div id="displayCart"></div>
</div>
</div>
<div class="footer">
<p class="copyright">Website created by Ruchira, Sam, Batuhan, and Kene</p>
</div>
<div id="Cart" class="tabcontent">
<h3>Cart</h3>
<p>Here is your cart.</p>
<div id="displayCart"></div>
<script src="scripts/groceries.js"></script>
<div class="footer">
<p class="copyright">
Website created by Ruchira, Sam, Batuhan, and Kene
</p>
</div>
<script src="scripts/main.js"></script>
</div>
</body>
</html>
<script src="scripts/groceries.js"></script>
<script src="scripts/main.js"></script>
</body>
</html>

View file

@ -8,70 +8,80 @@ var products = [
vegetarian: true,
glutenFree: true,
organic: true,
price: 1.99
price: 1.99,
productImg: "images/broccoli.png"
},
{
name: "bread",
vegetarian: true,
glutenFree: false,
organic: false,
price: 2.35
price: 2.35,
productImg: "images/bread.png"
},
{
name: "salmon",
vegetarian: false,
glutenFree: true,
organic: false,
price: 10.00
price: 10.00,
productImg: "images/salmon.png"
},
{
name: "carrot",
vegetarian: true,
glutenFree: true,
organic: true,
price: 2.63
price: 2.63,
productImg: "images/carrot.png"
},
{
name: "chicken",
vegetarian: false,
glutenFree: true,
organic: false,
price: 6.87
price: 6.87,
productImg: "images/chicken.png"
},
{
name: "cereal",
vegetarian: false,
glutenFree: false,
organic: false,
price: 2.97
price: 2.97,
productImg: "images/cereal.png"
},
{
name: "cheese",
vegetarian: false,
glutenFree: false,
organic: false,
price: 5.14
price: 5.14,
productImg: "images/cheese.png"
},
{
name: "white fish",
vegetarian: false,
glutenFree: true,
organic: false,
price: 13.50
price: 13.50,
productImg: "images/white-fish.png"
},
{
name: "honey",
vegetarian: false,
glutenFree: false,
organic: true,
price: 1.89
price: 1.89,
productImg: "images/honey.png"
},
{
name: "onion",
vegetarian: true,
glutenFree: true,
organic: true,
price: 2.22
price: 2.22,
productImg: "images/onion.png"
}
];
@ -79,6 +89,11 @@ products.sort(function(a, b) {
return a.price - b.price;
})
function getProductImg(productName) {
var prodVal = products.find(prod => prod.name === productName);
return prodVal.productImg;
}
// given restrictions provided, make a reduced list of products
// prices should be included in this list, as well as a sort based on price
@ -101,7 +116,7 @@ function restrictListProducts(prods, restriction) {
else if ((restriction == "Non-Organic") && (prods[i].organic == false)){
product_names.push(prods[i].name);
}
else if (restriction == "None"){
else if ( restriction == "None") {
product_names.push(prods[i].name);
}
}
@ -110,7 +125,7 @@ function restrictListProducts(prods, restriction) {
// Calculate the total price of items, with received parameter being a list of products
function getTotalPrice(chosenProducts) {
totalPrice = 0;
var totalPrice = 0;
for (let i=0; i<products.length; i+=1) {
if (chosenProducts.indexOf(products[i].name) > -1){
totalPrice += products[i].price;

View file

@ -54,16 +54,30 @@ function populateListProductChoices(slct1, slct2) {
// create a label for the checkbox, and also add in HTML DOM
var label = document.createElement('label')
label.htmlFor = productName;
label.appendChild(document.createTextNode(productName));
//get price of an item
var itemPrice = getItemPrice(productName);
label.appendChild(document.createTextNode(" $" + itemPrice));
label.appendChild(document.createTextNode(productName + " $" + itemPrice));
// //get price of an item
// var itemPrice = getItemPrice(productName);
// label.appendChild(document.createTextNode(" $" + itemPrice));
s2.appendChild(label);
// create a breakline node and add in HTML DOM
s2.appendChild(document.createElement("br"));
s2.appendChild(document.createElement("br"));
//create <img src="">
var prodImg = document.createElement("img");
prodImg.src = getProductImg(productName);
// prodImg = document.getElementById("displayProduct");
// console.log("trial", prodImg.src);
s2.appendChild(prodImg);
//use this to space the images
s2.appendChild(document.createElement("br"));
s2.appendChild(document.createElement("br"));
}
}
@ -83,12 +97,23 @@ function selectedItems(){
var para = document.createElement("P");
para.innerHTML = "You selected : ";
para.appendChild(document.createElement("br"));
for (i = 0; i < ele.length; i++) {
if (ele[i].checked) {
para.appendChild(document.createTextNode(ele[i].value + " $" + getItemPrice(ele[i].value)));
para.appendChild(document.createElement("br"));
//adding the image
console.log(getProductImg(ele[i].value));
var cartImg = para.appendChild(document.createElement("img"));
cartImg.src = getProductImg(ele[i].value);
// para.appendChild(cartImg);
para.appendChild(document.createElement("br"));
chosenProducts.push(ele[i].value);
}
}
// add paragraph and total price

View file

@ -35,29 +35,37 @@
border: 1px solid #ccc;
border-top: none;
background-color: rgb(222, 224, 228);
}
.tablinks {
font-size: 20px;
}
/* title/header */
h1{
font-family: "Britannic Bold ", sans-serif;
font-weight: bolder;
font-size: 40px;
font-size: 50px;
color: #f7fcfc;
vertical-align: middle;
display: inline;
margin-right: 15px;
/* margin-right: 15px; */
}
/*footer with signatures */
.footer {
position: fixed;
left: 0;
.footer {
bottom: 0;
left: a;
width: 100%;
background-color: rgb(87, 139, 216);
color: rgb(255, 255, 255);
color: rgb(0, 0, 0);
text-align: center;
}
.copyright{
font-size: 15px;
}
.logo{
@ -65,14 +73,54 @@ h1{
height:auto;
vertical-align: middle;
margin-bottom: 10px;
}
body {
margin: 0px;
background-color: #66BFBF;
background-image: url("images/bg3.jpg");
text-align: center;
font-size : 20px;
}
img{
width: 30%;
padding: 3% 7%;
}
.company-name {
text-align: left;
}
.cart-img {
height: 5%;
width: 5%;
padding: 0;
padding-left: 15px;
margin-top: 20px;
/*
position: relative;
top: 40px;
*/
}
h3 {
font-size: 30px;
}
p {
font-size: 25px;
}
i {
font-size: 15px;
}
.block {
font-size: 15px;
}
.sumo{
font-size: 15px;
}