Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Dee Barizo
Dee Barizo
8,402 Points

Adding a Dynamic Map, Task 6/7 (Not Passing)

Here is my code:

var mapElement = new google.maps.Map(document.getElementById("map"),
        mapOptions);

It seems like it should pass but it's not passing. I used the same code on the Google Maps API except for changing the id to "map".

Here is the instructions: Set the "mapElement" using the native "document" object and the method "getElementById" and pass in the id for the "map".

Thanks.

6 Answers

Declare the div#map before the script tag, did work here.

Dee Barizo
Dee Barizo
8,402 Points

I figured it out. :)

It's supposed to be:

var mapElement = document.getElementById("map");

That doesn't work for me.

That's not working for me. Any ideas..?

David Badillo
PLUS
David Badillo
Courses Plus Student 7,046 Points

Neither of the proposed answers above (from OP and from Dee Barizo) work for me either. Could it possibly be some type of bug?

Nick Manring
Nick Manring
11,369 Points

Afraid to ask another question on the forum from getting flack from "following videos too closely" I was glad to find others in this same issue.

Task one just says to make a div with ID = map. But it doesn't declare where the div should close. So natrually I just put it together in one place.

After a day or two I'm glad to finally find the result.

Here is the entire <body> from my code challenge that passed.

<body> <div id="map"> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAn8fk75K8kCdW6pQ4B7yoBHJNrUbleieY&sensor=false"></script> </div>
<script type="text/javascript"> var mapOptions = { center: new google.maps.LatLng(28.42, -81.58), zoom: 18, mapTypeId: google.maps.MapTypeId.SATELLITE };

  var mapElement = document.getElementById("map");
  var theMap;
</script>

</body>

Armand Ramirez
Armand Ramirez
4,016 Points

Yes ... declare the <div id="map"> before the <script> tag. jquery is usually called in a $(document).ready(function(){ //script goes here }) That clears up referencing DOM elements that haven't been read yet by the browser.