Download this episode

Download Video

Description

This lesson shows how to utilize jQuery Events to create a simple game by writing and attaching anonymous functions to events fired on a web page.

Tag:

JavaScript

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • asok14215

      There's some subtlety as to why the score variable can retain its value between clicks. I understand it because of my experience with C#, lambda expressions, and closures, but it might not be so obvious to the beginning programmer.

    • Ali

      Hi Bob , I really appreciate this series . it is so helpful and enlightening .

      I have two questions :
      if I have a loop ($.each) and inside I have a nested "if" statement when I am using the "return" keyword in the if statement it returns to the containing "each" statement instead of exit the function. what am I doing wrong ? ie:
      $('#btn').click(function () {
      var found = false;
      $.each(star1, function (i, val) {
      if (val == $('#starName').val()) {
      found = true;
      return ('found!!!'); // although that it is found the loop keep on going
      } else {
      if (i == (star1.length - 1)) {
      if (!found) {
      return ('not found');
      }//not found
      };
      };//end else
      });//end each

      });//end click

    • plok18644

      thank you bob tabor

    • guih6777

      I have never seen www.LearnVisualStudio.net

    • Jacob

      Hi Bob, is there a JQuery shortcut for every single Javascript command?

    • Jacob

      Also, I'm a little confused regarding the src script with the following anchor tag: http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.1.js

      Are we supposed to download jQuery, or can we just link all of our html files to that address?

      Thanks in advance.

    • BobTabor

      @Ali: When you put () around the value you're returning, you confuse javascript ... you're saying you want to call a method called return instead of the keyword.  Remove the () around ('found!!!') and I'm betting it will work.  Good luck!

      @Bob tabor is a idoit: . . . classy.  And grammatically challenged.

      @plok18644: You're welcome!

      @guih6777: How did you miss it!?  Wink

      @lib115634: Sorry?

      @Jacob: re: shortcuts ... I don't think so.  Just for the ones that are laborious to write.

      @Jacob: re: download ... You only reference THAT SINGLE FILE, the actual jQuery library file -->  jquery-1.7.1.js ... it is located at a number of web sites where it can be quickly downloaded (or perhaps even cached, if other web site builders like yourself use the same exact URL to host the file).  The remainder of your HTML , CSS and image files will point to YOUR domain name.  Hope that helps!

       

    • rohit

      hi bob,
      I feel like a devloper.

      Thanks.

    • TinTin

      So if I want to reset the score when I click Start Over, how would the code look like(what do U have to modify)?

    • BobTabor

      @TinTin: Hi TinTin ... I'm am absolutely NOT trying to be a smart aleck in what I'm about to say ... I believe in the "teach a man to fish and he'll fish for himself the rest of his life" philosophy.  So, tell me what you've tried already and let me walk you through it if you get stuck.  Hopefully if you've been following along up to this point, you should be able to do exactly what you're asking. 

      If you don't struggle, you don't truly learn.

    • TinTin

      Hello Bob,

      Thank you for the reply, I figured it out, had a bug in my code. The text would reset when I clicked start over, but it would display the score being 0 only after I hovered it one more time :))

      It is fixed now.

      Thanks for the series!

    • TinTin

      Hello Bob,

      Thank you for the reply, I figured it out, had a bug in my code. The text would reset when I clicked start over, but it would display the score being 0 only after I hovered it one more time :))

      It is fixed now.

      Thanks for the series!

    • Gowri

      need videos related to proxy in javascript

    • Mohamed

      Thank you Bob Tabor

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.