Skip to content

thoughtworks-jumpstart/js-basics-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JS Basics

  • Open the project in Visual Studio Code
  • Start the Live Server
  • Open the Console tab on Chrome's DevTools

Exercise 3: Objects and methods

  1. Define a new object called dog:

    • Give it a property name, set it to any value
    • Give it a method bark, which will log "woof!" to the console when invoked
    • Log dog.name to the console
    • Invoke dog.bark()
    • Log dog to the console
  2. Update the method bark above to say "woof, I'm <name>!"

    • e.g. if dog.name is "Timmy", dog.bark() should print "woof, I'm Timmy!" on the console
  3. Define a new object called person

    • Give it a firstName property
    • Give it a lastName property
    • Give it a name method that returns the full name of the person
    • Give it a birthYear property
    • Give it an ageThisYear method that returns the age of the person
      • e.g. if person.birthYear is 2000 then person.ageThisYear() should return 18
  4. Define a variable called someString with any string as its value

  5. Log the above string's length property to the console

  6. Set the length of someString to another number e.g. 200

  7. Log the length property of someString to the console again. Did it change? Why or why not?

  8. Explore some more string methods e.g. toLowerCase(), replace() etc. ([refer to MDN][mdn-string])

  9. Create a variable called decimalNumber, giving it some numeric value

  10. Use the toFixed() method to convert the number to a formatted string with 3 decimal places, and log it to the console

  11. Declare a function sum that takes in two arguments and returns the sum of the two arguments

  12. Log the value of the sum function's name property to the console

  13. Log the return value of the sum function's toString() method to the console

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published