Objects and Functions

In this example below you will see how to do a Objects and Functions with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by Corpheus91, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Corpheus91 ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Objects and Functions</title>
  
  
  
  
  
</head>

<body>

  
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/Corpheus91/objects-and-functions-XeRjmW */
const dog = {}
dog['name'] = 'Fido'
dog['age'] = 5
dog['breed'] = 'Aussie Shepard'
dog['badHabit'] = 'barking'
dog['size'] = 'medium'
console.log(dog)

const dogTwo = {}

dogTwo.name = 'Lassie'
dogTwo.age = 7
dogTwo.breed = 'Border Collie'
dogTwo.badHabit = 'pulls on leash'
dogTwo.size = 'medium'

console.log(dogTwo)

const bark = () => console.log("woof")

dog.bark = bark

dog.bark()


const dogThree = {
  name: 'Scruffy',
  age: 4,
  breed: 'Chesapeake Bay Retriever',
  badHabit: 'digging',
  size: 'large',
  woof(){
    console.log('woof')
  },
  trick(trickName){
    console.log('Scruffy ',trickName)
  }
}

dogThree.woof()

const anotherDog = dogThree;

anotherDog.woof()


const blogPost = {
  category: 'general',
  title: '',
  content: '',
  rank: 1,
  aboutMe(){
    console.log("Title:", this.title)
    console.log("Content:", this.content)
    console.log("Rank", this.rank)
  },
}


const postOne = blogPost;

postOne.title = 'My First Post'
postOne.content = 'Yay! I made an object!'
postOne.rank = 2

postOne.aboutMe()

const postTwo = blogPost;

postTwo.title = "My Day Today"
postTwo.content = "I wrote some awesoe proofs."
postTwo.rank = 445

postTwo.aboutMe()

const postThree = blogPost;

postThree.likes = 20

const customAboutMe = (likes) => console.log("Likes:",likes)

postThree.customAboutMe = customAboutMe

postThree.customAboutMe(postThree.likes)

Comments