-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
var dev1 = { | ||
id: 1, | ||
name:"George", | ||
description:"George is probably the coolest iPhone to exist. Ever. Point blank, period.", | ||
hardware:"iphone", | ||
software:"apple", | ||
}; | ||
|
||
var dev2 = { | ||
id: 2, | ||
name:"Greyson", | ||
description:"Greyson is pretty cool.. I guess.", | ||
hardware:"iphone", | ||
software:"apple", | ||
}; | ||
|
||
var dev3 = { | ||
id: 3, | ||
name:"Linkin Park", | ||
description:'"The hardest part of ending is starting again."', | ||
hardware:"ipad", | ||
software:"apple", | ||
}; | ||
|
||
var dev4 = { | ||
id: 4, | ||
name:"Abercrombie", | ||
description:"To all the people that hated me in high school, I have the prettiest clothes you all wear now!!", | ||
hardware:"ipad", | ||
software:"apple", | ||
}; | ||
|
||
var dev5 = { | ||
id: 5, | ||
name:"Hulk", | ||
description:"Go ahead and HULK SMASH! this awesome computer stick into your USB.", | ||
hardware:"computerStick", | ||
software:"intel", | ||
}; | ||
|
||
var dev6 = { | ||
id: 6, | ||
name:"Captain America", | ||
description:'"Make America Great Again. Wait, thats someone else.."', | ||
hardware:"computerStick", | ||
software:"intel", | ||
}; | ||
|
||
var devices = [dev1, dev2, dev3, dev4, dev5, dev6]; | ||
|
||
function getCartItems(){ | ||
//initiate array for them | ||
var cart = new Array; | ||
//get them from local storage | ||
var cart_str = localStorage.getItem('cart'); | ||
//if there is at least one object already we need to convert it from JSON to string | ||
if (cart_str !== null) { | ||
cart = JSON.parse(cart_str); | ||
} | ||
return cart; | ||
} | ||
|
||
function show(){ | ||
var cart = getCartItems(); | ||
var html = ''; | ||
if(cart.length !== 0){ | ||
for(var i = 0; i < cart.length; i++){ | ||
var id = cart[i]; //this gets the id value from the cart | ||
for(int j = 0; j < devices.length; j++){ //iterate device list | ||
if(devices[j].id === id){ //match the id's | ||
html += '<div> <input class = "deviceCheckbox" type = "checkbox" id = "' + id + '"> </input>' + devices[j].name + '</div>'; //create listing of all the devices | ||
break; //break out of loop when we match | ||
} | ||
} | ||
} | ||
} | ||
else{ | ||
html += 'Shopping cart is empty.'; | ||
} | ||
|
||
document.getElementById('shoppingContainer').innerHTML = html; //adds what we just generated to the webpage | ||
|
||
var checkboxes = document.getElementsByClassName('deviceCheckbox'); //get all the checkboxes we just placed! | ||
for(int i = 0; i < checkboxes.length; i++){ | ||
checkboxes[i].addEventListener('click',addToSelected); //when we click on a checkbox, it should add that item to the selected local storage | ||
} | ||
|
||
} |