Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Labs 1 and 2 #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lab/lab1/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Is printMenu a function? Answer this question with underscore. Should evaluate
to true.
===================== */

var query1;
var query1 = _.isFunction(printMenu);

console.log('printMenu is a function:', query1);

Expand All @@ -75,7 +75,7 @@ Is bakedGoods an array? Answer this question with underscore. Should evaluate
to true.
===================== */

var query2;
var query2 = _.isArray(bakedGoods);

console.log('bakedGoods is an array:', query2);

Expand All @@ -84,39 +84,39 @@ Is the first element in bakedGoods an object? Answer this question with
underscore. Should evaluate to true.
===================== */

var query3;
var query3 = _.isObject(bakedGoods[0]);

console.log('The first element in bakedGoods is an object:', query3);

/* =====================
Use _.where to return all cakes. Or bread. Whichever is your favorite.
===================== */

var query4;
var query4 = _.where(bakedGoods, {type:"Bread"});

console.log('All bread. Or cakes:', query4);

/* =====================
Use _.filter to return all baked goods that cost more than $4.
===================== */

var query5;
var query5 = _.filter(bakedGoods, function(bakedGoods) {return bakedGoods['price'] > 4;});

console.log('More than $4:', query5);

/* =====================
Use _.sortBy to order the list by inventory (from lowest to highest).
===================== */

var query6;
var query6 = _.sortBy(bakedGoods, 'inventory');

console.log('Sorted by inventory (lowest to highest):', query6);

/* =====================
Use _.groupBy to organize the baked goods by type.
===================== */

var query7;
var query7 = _.groupBy(bakedGoods, 'type');

console.log('Grouped by type:', query7);

Expand All @@ -140,8 +140,12 @@ Rye ... $5.09
Whole Wheat ... $4.49

===================== */
var printMenu2 = function(bakedGoods) {
var food = _.template(bakedGoods, "<%= food.name %> ... $<%= food.price %>");
return printMenu2({food.name: 'moe'})
};

// printMenu2(query7);
printMenu2(query7);

/* =====================
Stretch Goal (seriously, this is a bit tough at first!):
Expand Down
2 changes: 2 additions & 0 deletions lab/lab2/js/part1-ajax-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ var Stamen_TonerLite = L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/ton
maxZoom: 20,
ext: 'png'
}).addTo(map);

var worldCap = $.ajax( "https://raw.githubusercontent.com/MUSA611-CPLN692-spring2020/datasets/master/json/world-country-capitals.json" ).done(function(x) {console.log(x)});
40 changes: 35 additions & 5 deletions lab/lab2/js/part2-app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,45 @@
===================== */

// Use the data source URL from lab 1 in this 'ajax' function:
var downloadData = $.ajax("http://");
var downloadData = $.ajax("https://raw.githubusercontent.com/MUSA611-CPLN692-spring2020/datasets/master/json/world-country-capitals.json");

// Write a function to prepare your data (clean it up, organize it
// as you like, create fields, etc)
var parseData = function() {};
var parseData = function(downloadData) {
var countries = JSON.parse(downloadData);

var markerCoordinates = countries.map(function(country) {
var coords = {
lat: country.CapitalLatitude,
long: country.CapitalLongitude
};

return coords;
});

return markerCoordinates;
};

// Write a function to use your parsed data to create a bunch of
// marker objects (don't plot them!)
var makeMarkers = function() {};
var makeMarkers = function(parsedData) {
var markers = [];

markers = parsedData.map(function(coords){
return L.marker([coords.lat, coords.long]);
});


return markers;
};

// Now we need a function that takes this collection of markers
// and puts them on the map
var plotMarkers = function() {};
var plotMarkers = function(markers) {
markers.forEach(function(marker){
return marker.addTo(map);
});
};

// At this point you should see a bunch of markers on your map if
// things went well.
Expand All @@ -66,7 +92,11 @@ var plotMarkers = function() {};

// Look to the bottom of this file and try to reason about what this
// function should look like
var removeMarkers = function() {};
// var removeMarkers = function(markers) {
// markers.forEach(function(marker){
// return map.removeLayer(marker);
// });
// };

/* =====================
Optional, stretch goal
Expand Down