Learn Java Coding From Digital Marketing agencies in Bangalore
Good practice all around. So we do have slight Stiv. The DVD was a planet in here we can attach a button and basically when someone clicks on the button click for a planet when someone clicks on the button we want to Learn Java Coding From Digital Marketing agencies in Bangalore append something to the DivX child so we're going to start adding planets down below. It's going to close the console tab and what we will do is let's grab out Konst my div equals document get element by id Konst my button equals my div query selector button that's what we want. OK, so we'll attach an event listener to button my button add an event listener and of course we want to attach the click listener. Let's just do kind of an anonymous function in here, for now, we can do the function and no no let's do it as a named callback instead. So we can do get the planet initially.
So let's define that function get planet and we will move our fetch into the function like so and instead of cancel logging, we can invoke another function from an inside planet so we can invoke online marketing services. So function pop views the planet with the planet objects the new paragraph equals document create element the element we want to create. Let's just make it a paragraph tag. And new paragraph in our text equals planet if we only care about the name so just to Planet object or name finally will grab my div or append a new child node which is our new paragraph.
This should be enough to work. Everything looks in order. Let's check it out. You know what output I'll pop this into a separate tab Let's click for planet cool. Definitely works and you can see Digital Marketing agencies in Bangalore that we didn't get something immediately because we had to go and fetch the data regularly. This is asynchronous. We click again and it just had to win every time because of that planet one. Obviously, if we change this the planet too. No, I'm just curious what planet is at this point. All they're on makes sense. And if you want some element of pseudorandomness in here we can just do simple math thought random so we could do Konst random number equals.
First, we can say the math floor which will give us a nice integer. No dought something and we will do the math for on math or at random times math at random you can say times. Let's say you wanted a number Of Digital Marketing agencies in Bangalore. So math is in and times. My top floor has a result of rounding down so we can add to it plus and then we can just interpret this random number inside our fetch string right so we can use something like this with tactics and I'm numb and this should give us a random number between and. Every time we hit get planet which will happen every time we click on the button because of our callback here right.
Let's test it out. Boom boom boom boom croissant. Right there's only to choose from in our particular case. Not sure how many there Digital Marketing agencies in Bangalore is total in the Star Wars API but as you can imagine this is pretty useful too to kind of practice with it look at all these cool planets we got. Of course, we get repeats every now and then but hey we're definitely fetching something.
WEBVTT That you know the basics of how works. Let's have some more fun with it and we can use some of our new iOS knowledge to kind of tinker around. So one thing we could do is I noticed that we're only using planet Daut name which if we're only doing that we're getting an entire planet object but what we can do is we can just snatch out the name field or whatever object we're passing and we have seen Digital Marketing agencies in Bangalore this before and we're kind of snatching that out of the argument just by grabbing the name field and we can now just use this.
Right so if I comment this stuff out and we take a look at that and we'll be able to see something interesting right. Collins LUGG name will be ABC just the name here. So let's refresh. Open up my dev tools and this click for a planet and there we see just the name. Pretty cool stuff. So we can definitely do that if we want to justify Digital Marketing agencies in Bangalore. Name refresh here it's going to work as it was before and it really depends on your use case. Another thing we could do is you know since we're passing an entire planet object let me undo some of what I just did.
But getting past an entire planet object. And if we take a look at that in the console planet in the chrome dev tools you can see that there's a lot of fields that we aren't currently using. For example, climate diameter gravity name while we're using the name but we're now using orbital period population et cetera. So this is something cool that we can use to kind of practice our new knowledge of not just objects in general how to access objects or nested objects. If we ever need to. And also how to do things like restructuring. So let's see Digital Marketing agencies in Bangalore how we can do that soon. Right now we're taking in an entire planet object.
And what I want to do is instead of just showing the name I want to kind of create a new No that's sort of a separate div that has more info about the planet that this could be some kind of I don't know system where the user clicks and they just want to see some kind of random planet you know from Star Wars lore. So let's go ahead and do that. So the first thing I want to do is you know what I mean erase this code because we're going to do it a different way. And what I want is I want to grab out the certain fields from Planet object right. I can do something like Konst name equals Obstat name