From 307d7d1876b6ad1900997e7a6eb8ef05c28030bd Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Fri, 2 Apr 2021 15:29:15 -0400 Subject: [PATCH] Update javascript class --- ...ipt SuperHero and SuperVillain classes.zip | Bin 0 -> 2379 bytes .../hero.js | 70 ++++++++++++++ .../index.html | 33 +++++++ .../LAB Grocery list.zip | Bin 0 -> 2358 bytes .../10.15-lab-grocery-list/groceries.js | 88 ++++++++++++++++++ .../week11/10.15-lab-grocery-list/index.html | 17 ++++ 6 files changed, 208 insertions(+) create mode 100644 html-java-script/week11/10.14-lab-superhero-supervillain-classes/LAB JavaScript SuperHero and SuperVillain classes.zip create mode 100644 html-java-script/week11/10.14-lab-superhero-supervillain-classes/hero.js create mode 100644 html-java-script/week11/10.14-lab-superhero-supervillain-classes/index.html create mode 100644 html-java-script/week11/10.15-lab-grocery-list/LAB Grocery list.zip create mode 100644 html-java-script/week11/10.15-lab-grocery-list/groceries.js create mode 100644 html-java-script/week11/10.15-lab-grocery-list/index.html 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 0000000000000000000000000000000000000000..ff52b8a98998fbff79c548091726f352d97bb714 GIT binary patch literal 2379 zcmb7G!EW0|5M`aFu?6^+516tS385vVMS|9$4K%VFBerTHF;WCY4;ykNZB6Z}yGz+Z zkxNbil4C!r#{l_-d`M?@X_7K6B$X_X+?{#zX7hP?*^NjLGU1X^DJn5I(RQ+ z#xMI*JImv54^D??FOx%{r~U0tOjpR6oa}{MhPbj7TVZp)|Gb!U4M$unZeU^h;1^zq zJZD0hc;L;*!K7NuEf}5dg;R9s|7pVgc;J^Eq_IncMBA-bDqF(ebhkBD((a7eOytX5 z_*n~gH5szG z#rndC=>^YKfrV~H!U{O1KJ&r+hO8F;gxZOf8#m{6Hs$bCopWQkUJY3#H)0dXEizk| z-U+{i6D8LIoK2ZLS6`YD&|zE%iFl+YN)-iA9(z1+0#1(aY`)+4^zp++5YR7K+Xr{B z4@zyOIWxw~`KZ8?aB{>mHC7j?Rk|zLj7Kn67hIokJcXVYtepzer#;vMx;R<7#o83N z>IX7F+2Y@JXE1;RJ{FRffl+$EWagjBrUJ(d+YO0wa-y#z=A?=ndyYxyThR$I+y%)m zYS3=@l%?lzD&#rVErJ!>2)^${NGiP2Y1=#DC;&(_o|N~mOe1*Uotr9d0~`n@8RjYt zr|>Jr5&Y;OS}Jej44GCr9N}c*+7MFPCxV}PWqEy-N`+T-YKpoY!4>LPW~}g;u2@I# zLz!)*`ZmIdUBaO-TuzzJtV_4Hj^Lq3sM?|pP;X&^&4==w%8qF}UTvUTeOpxnyCzc? zeU@d13oh-6z^=wN>V^lWqajXRT2n0J8B)&F%-{D=uG^h)AyXQ5^?KLK-wD{#;PexS zY}D8Z(+Rn(J*q2HX)(hP{l5yXmwwz}SB2kE|CQ6HcLTW;$HRm~Qw12hm5i9JM_nCj z{~H*gugB|BK-aZZHQFYw6BkUEYr)W?2Wx1|iU0rr literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..b206e9adbe707274df02dcba322a81657858d460 GIT binary patch literal 2358 zcmbtW-EPxJ6gIF6RkXe10S*R-~n_aK< z0@uwox*w~20U!Mx8VXhFy9JvHxwsDxE5YP0JmK<`Ymu>Cs99Oxt$8Ji2R>+N^Y(+p zNu5<v)j#?HVGmafG0SlT7~EfQ|-VC=unX(V!PIp2nJg&@qTS zjfLjZcmQjw$BoviwCgO-A8EWkWwOD*hk5R(BDR!7MEG-VjWA0lIjh1vLo#^M`)(IW zpL#MFkFIU89|zyQT#6$4jxTKSU)bW1Ajvh@`vtWQQh5CzGQHjD_u*eAG&H3a682s` z2T_AmEa&-lXO1dS^B(SW|CE=SB6-QHZj63IY$(}`YrG3ZQ)XJIvb*E@o~x{xqDSw2 zgNixil4n|B>`h19&N+EADYAE%%(@KeZpRAZ!fY*p|Ci4@wHZxcaPI^k^n`nIKoUDe zrKU(i#^fPFW+&XZuk%M75g}a*(0GUfx`9_u^72GaU;ux6QcxRMbx+hY$rh%VS4g2M z=u(?Vcc2Q7h-w7Un4q4h`BQZ2lBc5w%}X$;?AUNw^VR%e$rs9QO)JQ4bzhj5>{xOm zyGKUe-GX7XOT5I)fSH$cZ{)IX`~l%&A__J9nRu|u-tKrYz}e*1lKU^Y8zchmV4E&`-v>?k3}o+xn;=)i0mJ;|4t#Bzyi&;GvxJfgs0L|b4pzd@FtaSF?u1T zrfeJEGpAKgS7Pdf3nW?!JzuS78>p+sivu^gPN$t!G>20#YwAg>Rj)df)~j5brQYkg4wJ9%~5Vlw55%0qkeAR4wPd;@0`R3Tx%cvzV&7}kg?KPy8uogpNf#g9Y{$6Ts8QRz+Q z31Fk$gt#27!?{hdzMHNAlvOf%l#RZZ_dZ{ZBKnR;mo8tAR_`m}V~*Ze)<3Jam(92^ iCp`pLpKtiUv`w<_4CB$CST~9;<6njUzv7!x6#WDaZLu%_ literal 0 HcmV?d00001 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