Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sabrina Powell Workshop Files #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tryJS/code/arrayActivity.js
Original file line number Diff line number Diff line change
@@ -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);
39 changes: 39 additions & 0 deletions tryJS/code/conditionActivity.js
Original file line number Diff line number Diff line change
@@ -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/

21 changes: 21 additions & 0 deletions tryJS/code/dataTypesActivity.js
Original file line number Diff line number Diff line change
@@ -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);
39 changes: 39 additions & 0 deletions tryJS/code/forLoopActivity.js
Original file line number Diff line number Diff line change
@@ -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}`);
}
}
51 changes: 51 additions & 0 deletions tryJS/code/functionActivity.js
Original file line number Diff line number Diff line change
@@ -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);
13 changes: 13 additions & 0 deletions tryJS/code/test.js
Original file line number Diff line number Diff line change
@@ -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);
11 changes: 11 additions & 0 deletions tryJS/package.json
Original file line number Diff line number Diff line change
@@ -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"
}