YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Click Metrics - JavaScript Basics

Get Embed Code
5 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. Now that our code is inside a function,
  2. it has to be called, otherwise it won't work.
  3. So let's invoke our code right after we define it.
  4. Now first I'm going to give myself a little bit more space here so
  5. you can see what I'm writing, and if we call display work and save it and
  6. refresh the page, we can see that our work experience appears right here.
  7. >> Hm, so, James, when you wrote display work, you didn't put an argument in,
  8. you didn't pass in a parameter.
  9. That's pretty interesting, why didn't we have to use one?
  10. >> Well, this function is using an object that's in the global scope for
  11. the script, meaning it's accessible to the function which is also in
  12. the global scope.
  13. >> True, but let's imagine that we wanted to,
  14. I don't know, for some reason, add multiple different work sessions to the page.
  15. Then, what would be need to do?
  16. >> That sounds like a job for an argument.
  17. If this function took in an argument, we could pass it different work objects,
  18. which would each get displayed on the page.
  19. >> You think we should do that?
  20. >> I'm having a hard time imagining, why you want to do that for this example.
  21. I have a better idea.
  22. Lets say you wanted to track where users are clicking on your site.
  23. We could collect the cursor location every time a user clicks on the page and
  24. send that off to our analytics site.
  25. >> Interesting, let's see how that works.