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 trialDee Barizo
8,402 PointsAdding 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
Rafael Louro
4,699 PointsDeclare the div#map before the script tag, did work here.
Dee Barizo
8,402 PointsI figured it out. :)
It's supposed to be:
var mapElement = document.getElementById("map");
Alex Plaza
22,923 Pointsgreat! thanks!
Steven Wade
6,425 PointsThat doesn't work for me.
Michael Avery
10,568 PointsThat's not working for me. Any ideas..?
David Badillo
Courses Plus Student 7,046 PointsNeither 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
11,369 PointsAfraid 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
4,016 PointsYes ... 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.