working on functions

pull/73/head
Derrek Gass 5 years ago
parent 26219cf5d4
commit 02408b9725

@ -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
}

@ -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',
}
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'))
Loading…
Cancel
Save