Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

syntax javascript/jquery

hi guys I’m trying to build something but the hardest part for me is understanding where and what to do with the syntax. For this little game I want the dragon to explode when the blue fire ball (hadouken) reaches the dragon. I tried using the offset position to get the position of the dragon and fireball and then used an ‘if statement’, but I can’t get it to work. First question: does var dragon_Position = $(".dragon").offset() get the location of the offset and now all I have to do is use the variable dragon_Position to use it or do I have to get the value somehow of the offset()?. Like using val() or get element id? Second I did a test by making the dragon explode when you click on him. But he wont come back when you click again. Curious to know how to do that. Any advice on structuring jquery syntax

http://codepen.io/mbrwn/pen/rOBpeM

var dragon_Position = $(".dragon").offset()
var hadouken_Position = $(".hadouken").offset()

if (dragon_Position == hadouken_Position ) {
        $('dragon').explode;        
   };

});

2 Answers

I believe the offset() method returns the coordinates of the selected element.

For your following code here:

    $('#explosion').click(function() {
       $("#explosion").toggle( "explode" );
    });

 var dragon_Position = $(".dragon").offset()
 var hadouken_Position = $(".hadouken").offset()

 if (dragon_Position == hadouken_Position ) {
        $('dragon').explode;        
 };

Where is "explode" coming from?

You have also selected the class ".dragon" however I cannot see any dragon class in your HTML.

hi sorry forgot to update the codepen i was mainly working in sublime. just update the ids the explosion id is now dragon and the explode is a jquery effect https://api.jqueryui.com/explode-effect/