Code Monkey home page Code Monkey logo

lab-101-js-intro's Introduction

The Purpose of this Lesson!

Javascript allows your page to become more interactive:

  • Strings
  • Numbers
  • Variables
  • Functions
  • Buttons
  • Events

Some things in JavaScript, like HTML elements, have special functions attached to them with a dot (.). Both getElementById and addEventListener are examples. Functions like this are often called methods. To better understand events and callbacks, think of a child out playing while her dad cooks dinner. Whenever dinner is done (the event), he'll call her back inside to eat (the callback). Some will say the event was triggered or fired โ€” a lot of gun metaphors, for some reason.

<script>
      var tellJoke = function () {
        var joke = 'Why did the chicken cross the road?'
        var punchline = 'To get to the Other Side!'
        
        alert(joke)
        alert(punchline)
        
        }
</script>

This code contains a function, you can call the function by tellJoke().

<script>
      tellJoke = function (joke, punchline) {
        alert(joke)
        alert(punchline)
      }
</script>

This code contains a function, allows the user to pass values through this function such as tellJoke(joke, punchline).

<script>
      var buttonElement = document.getElementById('my-first-button')
      buttonElement.addEventListener('click', function() {
        alert(joke)
        alert(punchline)
      })

      var joke = 'Why did the chicken cross the road?'
      var punchline = 'To get to the Other Side!'
    </script>

Inside the HTML, there would be a button or an element with the id of buttonElement that is traced and watched. Once this button or element has been 'clicked', it would start to run whatever is inside the function.

lab-101-js-intro's People

Contributors

vincentmaule avatar

Watchers

Erik Gillespie avatar  avatar

lab-101-js-intro's Issues

Project Feedback

Build a virtual drum kit (or sound mixer)

@egillespie Can you take a look at this? It's hosted here and meets the following criteria:

  • At least 3 button elements are included in your page
  • When each of the buttons is hovered over (mouseenter event) or clicked on (click event), a unique sound effect plays from an audio element (try the .play() method) -- you may use these drum kit sounds or use any other sounds that won't hurt/irritate the people who listen to them
  • Each button is well-labeled, corresponding to the sound it will play
  • All audio elements are invisible (no controls attribute), so that they can only be played with the buttons
  • All of your JavaScript is in a separate file ending with .js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.