diff --git a/tryJS/code/arrayActivity.js b/tryJS/code/arrayActivity.js new file mode 100644 index 0000000..a13765a --- /dev/null +++ b/tryJS/code/arrayActivity.js @@ -0,0 +1,48 @@ +let druids = [ + { + "age": 5, + "armor": "Bronze", + "killsOnBattleField": 21 + }, + { + "age": 9, + "armor": "Bronze", + "killsOnBattleField": 42 + }, + { + "age": 14, + "armor": "Bronze", + "killsOnBattleField": 79 + }, + { + "age": 15, + "armor": "Silver Maximum", + "killsOnBattleField": 98 + }, + { + "age": 15, + "armor": "Silver", + "killsOnBattleField": 74 + }, + { + "age": 20, + "armor": "Titanium", + "killsOnBattleField": 491 + } +]; + +function filterDruidsUnder15(druid) { + return druid.age < 15; +} + +let under15Druids = druids.filter(filterDruidsUnder15); +console.log(under15Druids); + +function alterDruidsAge(druid) { + let newDruid = druid; + newDruid.age--; + return newDruid; +} + +let druidsList = druids.map(alterDruidsAge); +console.log(druidsList); diff --git a/tryJS/code/conditionActivity.js b/tryJS/code/conditionActivity.js new file mode 100644 index 0000000..8d9cb46 --- /dev/null +++ b/tryJS/code/conditionActivity.js @@ -0,0 +1,39 @@ +let druids = [ + { + "age": 5, + "armor": "", + "killsOnBattleField": 21 + }, + { + "age": 15, + "armor": "", + "killsOnBattleField": 98 + }, + { + "age": 15, + "armor": "", + "killsOnBattleField": 74 + }, + { + "age": 20, + "armor": "", + "killsOnBattleField": 491 + } +]; + +for (let i = 0; i < druids.length; i++) { + if (druids[i].age < 15) + druids[i].armor = "Bronze"; + else if (druids[i].age >= 15 && druids[i].age < 20) + if (druids[i].killsOnBattleField > 90) + druids[i].armor = "Silver Maximum"; + else + druids[i].armor = "Silver "; + else + druids[i].armor = "Titanium"; + + console.log(druids[i]); +} + +//Ran in https://jsconsole.com/ + diff --git a/tryJS/code/dataTypesActivity.js b/tryJS/code/dataTypesActivity.js new file mode 100644 index 0000000..428348c --- /dev/null +++ b/tryJS/code/dataTypesActivity.js @@ -0,0 +1,21 @@ +let arrOriginal = [1,2,3,4,5]; +console.log('Original: ' + arrOriginal); + +let arrReversed = [ + arrOriginal[4], + arrOriginal[3], + arrOriginal[2], + arrOriginal[1], + arrOriginal[0] +]; +console.log('Reversed: ' + arrReversed); + +let employee = { + "fullName": "Chris Watts", + "position": "HR", + "age": "27", + "gender": "male" +} + +let empString = `${employee.fullName} is a ${employee.age} years old ${employee.gender} working in ${employee.position}.`; +console.log(empString); \ No newline at end of file diff --git a/tryJS/code/forLoopActivity.js b/tryJS/code/forLoopActivity.js new file mode 100644 index 0000000..025452b --- /dev/null +++ b/tryJS/code/forLoopActivity.js @@ -0,0 +1,39 @@ +let druids = [ + { + "age": 5, + "armor": "Bronze", + "killsOnBattleField": 21 + }, + { + "age": 9, + "armor": "Bronze", + "killsOnBattleField": 42 + }, + { + "age": 14, + "armor": "Bronze", + "killsOnBattleField": 79 + }, + { + "age": 15, + "armor": "Silver Maximum", + "killsOnBattleField": 98 + }, + { + "age": 15, + "armor": "Silver", + "killsOnBattleField": 74 + }, + { + "age": 20, + "armor": "Titanium", + "killsOnBattleField": 491 + } +]; + +for (const druid of druids) { + for (const key in druid) { + const element = druid[key]; + console.log(`${key} -> ${element}`); + } +} \ No newline at end of file diff --git a/tryJS/code/functionActivity.js b/tryJS/code/functionActivity.js new file mode 100644 index 0000000..d0a28ad --- /dev/null +++ b/tryJS/code/functionActivity.js @@ -0,0 +1,51 @@ +let druid = { + "age": 5, + "armor": "Bronze", + "killsOnBattleField": 21 +} + +function updateDruidAge(myDruid, age) { + myDruid.age = age; + return myDruid; +} + +function checkUpgradeEligibility(myDruid) { + if (myDruid.age < 15 && myDruid.armor != "Bronze") + return true + else if (myDruid.age >= 15 && myDruid.age < 20) + if (myDruid.killsOnBattleField > 90 && myDruid.armor != "Silver Maximum") + return true; + else if (myDruid.armor != "Silver") + return true; + else if (myDruid.armor != "Titanium") + return true; + + return false; +} + +function upgradeDruidArmor(myDruid) { + if (myDruid.age < 15) + myDruid.armor = "Bronze"; + else if (myDruid.age >= 15 && myDruid.age < 20) + if (myDruid.killsOnBattleField > 90) + myDruid.armor = "Silver Maximum"; + else + myDruid.armor = "Silver "; + else + myDruid.armor = "Titanium"; + + return myDruid; +} + +function displayDruid (myDruid) { + return 'Age: ' + myDruid.age + "\nArmor: " + myDruid.armor + "\nKills: " + myDruid.killsOnBattleField; +} + +let updatedDruid = updateDruidAge(druid, 15); +displayDruid(updatedDruid); + +let isEligible = checkUpgradeEligibility(updatedDruid); +if (isEligible) + updatedDruid = upgradeDruidArmor(updatedDruid); + +displayDruid(updatedDruid); \ No newline at end of file diff --git a/tryJS/code/test.js b/tryJS/code/test.js new file mode 100644 index 0000000..f2a80c4 --- /dev/null +++ b/tryJS/code/test.js @@ -0,0 +1,13 @@ +const myArray2 = ['Hello from QW', 'Hello from another land', 'QW says hello'] + +function mapByWordsWithQW(value) { + let newValue = value + if(value.includes('QW')) { + newValue = value.replace('QW', 'QualityWorks') + } + return newValue +} + +const mappedList = myArray2.map(mapByWordsWithQW); +console.log(mappedList); +console.log(myArray2); \ No newline at end of file diff --git a/tryJS/package.json b/tryJS/package.json new file mode 100644 index 0000000..1fa7a4a --- /dev/null +++ b/tryJS/package.json @@ -0,0 +1,11 @@ +{ + "name": "tryjs", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Sabrina Powell", + "license": "ISC" +}