diff --git a/html-java-script/week11/10.14-lab-superhero-supervillain-classes/LAB JavaScript SuperHero and SuperVillain classes.zip b/html-java-script/week11/10.14-lab-superhero-supervillain-classes/LAB JavaScript SuperHero and SuperVillain classes.zip new file mode 100644 index 0000000..ff52b8a Binary files /dev/null and b/html-java-script/week11/10.14-lab-superhero-supervillain-classes/LAB JavaScript SuperHero and SuperVillain classes.zip differ diff --git a/html-java-script/week11/10.14-lab-superhero-supervillain-classes/hero.js b/html-java-script/week11/10.14-lab-superhero-supervillain-classes/hero.js new file mode 100644 index 0000000..ff7af31 --- /dev/null +++ b/html-java-script/week11/10.14-lab-superhero-supervillain-classes/hero.js @@ -0,0 +1,70 @@ +"use strict" +class SuperHuman { + constructor(name, powerLevel) { + this.name = name; + this.powerLevel = powerLevel; + } +} + +// Define SuperHero and SuperVillain classes here + +class SuperHero extends SuperHuman{ + constructor(name, alias, powerLevel){ + super(name, powerLevel); + this.alias = alias; + } + battle(sv){ + if (this.powerLevel >= sv.powerLevel){return true;} + else{return false;} + } +} + +class SuperVillain extends SuperHuman{ + constructor(name, alias, powerLevel){ + super(name, powerLevel); + this.alias = alias; + } + getEvilChuckle(){return "Ha ha ha!";} +} + +const heroes = { + "Super Bacon": new SuperHero("Jack Oinker", "Super Bacon", 2), + "Flat-Man": new SuperHero("Peter Pranker", "Flat-Man", 5), + "Mighty Woman": new SuperHero("Diana Dense", "Mighty Woman", 8), + "Captain Marvelous": new SuperHero("Carol Hangers", "Captain Marvelous", 9) +} + +const villains = { + "The Jokester": new SuperHero("Jack Nastier", "The Jokester", 3), + "Magnet Man": new SuperHero("Max Eisenhardt", "Magnet Man", 6), + "Lex Loner": new SuperHero("Lex Loner", "Lex Loner", 2), + "Thankos": new SuperHero("Thankos", "Thankos", 9) +} + +window.addEventListener("DOMContentLoaded", domLoaded); + +function domLoaded() { + // Detect selection of hero and villain + document.querySelector("#heroSelect").addEventListener("change", selectionChanged); + document.querySelector("#villainSelect").addEventListener("change", selectionChanged); + + selectionChanged(); +} + +function selectionChanged() { + var selectedHeroValue = document.querySelector("#heroSelect").value; + var selectedVillainValue = document.querySelector("#villainSelect").value; + + // Get hero and villain selected + var selectedHero = heroes[selectedHeroValue]; + var selectedVillain = villains[selectedVillainValue]; + + // Your code goes here + if (selectedHero.battle(selectedVillain)){ + document.querySelector("#winner").innerHTML = "Winner: " + selectedHero.alias + "!"; + } + else{ + document.querySelector("#winner").innerHTML = "Winner: " + selectedVillain.alias + "!"; + } + +} diff --git a/html-java-script/week11/10.14-lab-superhero-supervillain-classes/index.html b/html-java-script/week11/10.14-lab-superhero-supervillain-classes/index.html new file mode 100644 index 0000000..6bc044a --- /dev/null +++ b/html-java-script/week11/10.14-lab-superhero-supervillain-classes/index.html @@ -0,0 +1,33 @@ + + + Super Heroes vs. Super Villains + + + +

Super Heroes vs. Super Villains

+ +

Select a hero: + +

+ +

Select a villain: + +

+ +

+ + \ No newline at end of file diff --git a/html-java-script/week11/10.15-lab-grocery-list/LAB Grocery list.zip b/html-java-script/week11/10.15-lab-grocery-list/LAB Grocery list.zip new file mode 100644 index 0000000..b206e9a Binary files /dev/null and b/html-java-script/week11/10.15-lab-grocery-list/LAB Grocery list.zip differ diff --git a/html-java-script/week11/10.15-lab-grocery-list/groceries.js b/html-java-script/week11/10.15-lab-grocery-list/groceries.js new file mode 100644 index 0000000..9902192 --- /dev/null +++ b/html-java-script/week11/10.15-lab-grocery-list/groceries.js @@ -0,0 +1,88 @@ +"use strict" +let groceryList = []; + +// Wait until DOM is loaded +window.addEventListener("DOMContentLoaded", function() { + document.querySelector("#addBtn").addEventListener("click", addBtnClick); + document.querySelector("#clearBtn").addEventListener("click", clearBtnClick); + + // Load the grocery list from localStorage + groceryList = loadList(); + + if (groceryList.length > 0) { + // Display list + for (let item of groceryList) { + showItem(item); + } + } + else { + // No list to display + enableClearButton(false); + } +}); + +// Enable or disable the Clear button +function enableClearButton(enabled) { + document.querySelector("#clearBtn").disabled = !enabled; +} + +// Show item at end of the ordered list +function showItem(item) { + let list = document.querySelector("ol"); + list.innerHTML += `
  • ${item}
  • `; +} + +// Add item to grocery list +function addBtnClick() { + let itemTextInput = document.querySelector("#item"); + let item = itemTextInput.value.trim(); + if (item.length > 0) { + enableClearButton(true); + showItem(item); + groceryList.push(item); + + // Save groceryList to localStorage + saveList(groceryList); + } + + // Clear input + itemTextInput.value = ''; +} + +// Clear the list +function clearBtnClick() { + enableClearButton(false); + groceryList = []; + let list = document.querySelector("ol"); + list.innerHTML = ""; + + // Remove the grocery list from localStorage + clearList(); +} + +// Complete the functions below + +function loadList() { + let groceryList; + let storage; + groceryList = []; + + storage=localStorage.getItem("list"); + if (storage != null){ + groceryList = storage.split(","); + } + + return groceryList; + +} + +function saveList(groceryList) { + console.log(groceryList.toString()); + + localStorage.setItem("list", groceryList.toString()); + +} + +function clearList() { + localStorage.clear(); +} diff --git a/html-java-script/week11/10.15-lab-grocery-list/index.html b/html-java-script/week11/10.15-lab-grocery-list/index.html new file mode 100644 index 0000000..da9df1b --- /dev/null +++ b/html-java-script/week11/10.15-lab-grocery-list/index.html @@ -0,0 +1,17 @@ + + + Grocery List + + + + +

    Grocery List

    + +
      + + + \ No newline at end of file