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

workshop files #5

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
33 changes: 33 additions & 0 deletions nyran-moodie/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
let druidsArray = [
{
age: 1,
armor: '',
killsOnBattlefield: 900
},
{
age: 20,
armor: 'gold',
killsOnBattlefield: 900
},
{
age: 16,
armor: 'silver',
killsOnBattlefield: 900
},
{
age: 12,
armor: 'wood',
killsOnBattlefield: 900
},
]

let youngDruids = druidsArray.filter((item) => {
if (item.age < 15)
return item
})
console.log(youngDruids)

let subtractAge = druidsArray.map((item) => {
return { age: item.age - 1, ...item }
})
console.log(subtractAge)
21 changes: 21 additions & 0 deletions nyran-moodie/conditional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const druid = {
age: 58.9,
armor: '',
killsOnBattlefield: 900
}

if (druid.age >= 10 && druid.age <= 14) {
druid.armor = 'bronze armor'
}
if (druid.age >= 15 && druid.age < 20) {
if (druid.killsOnBattlefield >= 90) {
druid.armor = 'silver armor maximum'
} else {
druid.armor = 'silver armor'
}
}
if (druid.age >= 20) {
druid.armor = 'titanium armor'
}
druid.new = 888
console.log(druid)
18 changes: 18 additions & 0 deletions nyran-moodie/datatypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let number = [1, 2, 3, 4, 5]
console.log(number)

let reversed = [...number].reverse()
console.log(reversed)
let employee = {
FullName: 'Nyran Moodie',
Position: 'Developer',
Age: 44,
Gender: 'make'
}
console.log(employee)

console.log(`
Employee Name : ${employee.FullName} \n
Position : ${employee.Position}\n
Age : ${employee.Age} \n
Gender : ${employee.Gender}`)
23 changes: 23 additions & 0 deletions nyran-moodie/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let fruits = ['apple', 'grape', 'mango', 'apple', 'banana']

// function f(value) {
// return value === 'apple'
// }
// let filteredFruites = fruits.filter(f)

// console.log(filteredFruites)

// let replaceApple = fruits.map((item) => {
// if (item === 'apple') {
// return 'orange'
// } else {
// return item
// }


// })
//console.log(replaceApple)

let a = fruits.forEach((item) => {
item
})
29 changes: 29 additions & 0 deletions nyran-moodie/for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let druidsArray = [
{
age: 1,
armor: '',
killsOnBattlefield: 900
},
{
age: 20,
armor: 'gold',
killsOnBattlefield: 900
},
{
age: 16,
armor: 'silver',
killsOnBattlefield: 900
},
{
age: 12,
armor: 'wood',
killsOnBattlefield: 900
},
]

for (druid of druidsArray) {
for (item in druid) {
console.log(`${item} : ${druid[item]}`)
}
console.log('-------------------------------')
}
37 changes: 37 additions & 0 deletions nyran-moodie/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

const druid = {
age: 20,
armor: '',
killsOnBattlefield: 900
}

// function updateDruidAge(druidObject, newAge) {
// druidObject.age = newAge
// return druidObject
// }

// let newDruid = updateDruidAge(druid, 12)
// console.log(newDruid)

function checkUpgradeEligibility(druidObject) {
if (druidObject.armor === '' || druidObject.age < 10)
return false

if (druidObject.age >= 10 && druidObject.age <= 14) {
return true
}

if (druidObject.age >= 15 && druidObject.age < 20) {
if (druidObject.killsOnBattlefield >= 90) {
return true
} else {
return true
}
}
if (druidObject.age >= 20) {
return true
}
}

let canReceiveArmor = checkUpgradeEligibility(druid)
console.log(canReceiveArmor)
12 changes: 12 additions & 0 deletions nyran-moodie/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function killSomeone(isDead) {
if (isDead) {
return Promise.resolve('Wanted')
}
else {
Promise.reject('Free')
}


}

let police = killSomeone().then()