diff --git a/solutions/day-01/functions.js b/solutions/day-01/functions.js index e69de29..14924df 100644 --- a/solutions/day-01/functions.js +++ b/solutions/day-01/functions.js @@ -0,0 +1,35 @@ +function square() { + let num = 2 + let sq = num * num + console.log(sq) + } + +function addTwoNumbers(num1, num2) { + return num1 + num2 +} + +function printFullName() { + let firstName = 'Derrek' + let lastName = 'Gass' + let space = ' ' + let fullName = firstName + space + lastName + return fullName + } + +function areaOfCircle(radius) { + let area = Math.PI * radius * radius + return area +} + +function square(side) { + return side * side +} + +let numbers = [10, 20, 30, 40, 50] +function sum(arr) { + let sum = 0 + for (let i = 0; i < arr.length; i++){ + sum += arr[i] + } + return sum +} \ No newline at end of file diff --git a/solutions/day-01/objects.js b/solutions/day-01/objects.js index f05d922..b6b9648 100644 --- a/solutions/day-01/objects.js +++ b/solutions/day-01/objects.js @@ -1,7 +1,7 @@ const person = { - firstName: 'Asabeneh', - lastName: 'Yetayeh', - age: 250, + firstName: 'Derrek', + lastName: 'Gass', + age: 32, country: 'Finland', city: 'Helsinki', skills: [ @@ -15,7 +15,57 @@ const person = { 'D3.js', ], getFullName: function () { - return `${this.firstName}${this.lastName}` + return `${this.firstName} ${this.lastName}` }, 'phone number': '+3584545454545', - } \ No newline at end of file + getLocation: function () { + return `${this.city}, ${this.country}` + } +} + +console.log(person.getFullName()) +console.log(person.firstName, person.age) + +console.log(person['firstName']) +console.log(person.getLocation()) + +person.nationality = 'American' +person.country = 'America' +person.title = 'Software Developer Engineer' +person.skills.push('React') +person.skills.push('Node.js') +person.isMarried = false + +person.getPersonInfo = function () { + let skillsWithoutLastSkill = this.skills + .splice(0, this.skills.length - 1) + .join(', ') + let lastSkill = this.skills.splice(this.skills.length - 1)[0] + + let skills = `${skillsWithoutLastSkill}, and ${lastSkill}` + let fullName = this.getFullName() + let statement = `${fullName} is a ${this.title}.\nHe lives in ${this.country}.\nHe teaches ${skills}.` + return statement +} +person.setName = function (first, last) { + this.firstName = first + this.lastName = last +} + +console.log(person) +console.log(person.getPersonInfo()) + +const dupPerson = Object.assign({}, person) +dupPerson.setName('Stewart', 'Glass') +console.log(dupPerson.getPersonInfo()) + +const values = Object.values(dupPerson) +console.log(values) + +const keys = Object.keys(dupPerson) +console.log(keys) + +const entries = Object.entries(dupPerson) +console.log(entries) + +console.log(dupPerson.hasOwnProperty('skills')) \ No newline at end of file