In-class Exercise: JavaScript
Part 1: Look at dropdowns
- Open this example and copy the HTML (below the map) into a code editor (such as Brackets) and save it.
- Open the file in your browser.
- After the line
add the following linevar type = $('.type-picker').val();
console.log(type);
- Reload the file in your browser, open developer tools, and pick various options in the dropdown. In the console are you should see the value of the dropdown being written out each time it changes.
- We're going to do the same thing with the SQL. Just before the line
UsewatsanLayer.setSQL(sql);
console.log()
to log out the value of the variablesql
.
Part 2: Arrays
- Open a new tab in your browser and open developer tools.
- Copy and paste this code into the console:
and pressvar types = [ 'urban_agriculture', 'biocentre', 'toilet_public' ];
Enter
- In the console, type
and presstypes[0]
Enter
. - You should see the first item in
types
. - Do the same for the second and third items in
types
.
Part 3: Objects
- In the developer tools console, copy and paste this code:
var coordinates = { latitude: 41.56, longitude: -73.29 };
- Still in the console, type
and presscoordinates.latitude
Enter
. - In a similar way, get the longitude from
coordinates
.