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

assignment 2 #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Empty file added assignment/.Rhistory
Empty file.
33 changes: 29 additions & 4 deletions assignment/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,35 @@

===================== */

var jsonToCsv = function(json) { console.log(json); };


var addMarkers = function(map) {};
var header = [Object.keys(healthCenters[0])];
var TempArr = [Object.values(healthCenters)];
healthCentersArr = header.push(TempArr);
for (i=0; i < healthCentersArr.length; i++){console.log(healthCentersArr)};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are extremely close. But haven't quite gotten it.

header is an array that contains two sub arrays. The first is correct, but the second TempArr is an array with a collection of objects.

Do you see how these results looks different in the console:

image

versus
image

image


var addIcon1 = L.icon({
iconUrl: 'https://upload.wikimedia.org/wikipedia/commons/3/3d/Blue_dot.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
});
var addIcon2 = L.icon({
iconUrl: 'https://www.pngarts.com/files/4/Dot-PNG-Pic.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
});

var addMarkers1 = (map) => {return L.marker([obj[1],obj[0]]).bindPopuup(obj[3],{icon: addIcon1})};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - I am not seeing any markers appear on the map. Were you able to view them?

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you very nearly have it! It is very likely one line that needs to be fixed. But just try to run it again and see if you can find it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ross,
I fixed the code. It should be able to run this time!

var addMarkers2 = (map) => {return L.marker([obj[1],obj[0]]).bindPopuup(obj[3],{icon: addIcon2})};
for (var i = 0; i < healthCentersArr.length; i++) {
if(19140 <= healthCentersArr[i][5] <= 19149){
if (healthCentersArr[8] === "N/A"){
addMarkers1(healthCentersArr).addTo(map).bindPopup(healthCentersArr[i][3]);
} else {
addMarkers2(healthCentersArr).addTo(map).bindPopup(healthCentersArr[i][3]);
}
}
};

/* =====================

Expand Down
98 changes: 98 additions & 0 deletions assignment/part1-array-access.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html>
<head>
<!--stylesheet imports-->
<link rel="stylesheet" href="leaflet.css" />
</head>
<body>

<!--left panel-->
<div style="position: absolute; left: 0px; width: 400px; top: 0; bottom: 0;"></div>
<!--map-->
<div id="map" style="position: absolute; right: 0; left: 400px; top: 0; bottom: 0;"></div>

<!--javascript imports-->
<script src="leaflet.js"></script>

<script>

/* =====================

# Lab 1, Part 1 — Array Access

## Introduction

Refactor your week 1 homework assignment to leverage some of the Javascript
functionality we have been learning about. We will start by improving the
way we store data and the amount of times we call the L.marker method.

## Task 1: Data Storage

Let's consider a marker for a single restaurant point location. We could
store information about that marker as an array
([element1, element2, element3...]). Your point location array should
contain the following three elements in this order: 1. lat, 2. lng, 3. label.

Create an array of arrays (an array that contains multiple arrays) to
represent every restaurant in your restaurant data. Save this as variable
"restaurantData".

## Task 2: Process Data

Create a marker for each element in "restaurantData". Your final code should
only include "L.marker" one time.

## Task 3: Add Two Additional Markers

Add two additional restaurants to your data. You should only need to modify
"restaurantData" to do this. Confirm that these new markers are added to
your application.

## Task 4: Add Popups to Markers

Add popups to your markers. The popup should contain the label for your
restaurant. Refer to the Leaflet documentation for instructions on adding
a popup: http://leafletjs.com/reference.html#popup

===================== */

var map = L.map('map', {
center: [39.9522, -75.1639],
zoom: 14
});

var Stamen_TonerLite = L.tileLayer('http://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.{ext}', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20,
ext: 'png'
}).addTo(map);

/* =====================

Start code

===================== */

L.marker([0, 0]).addTo(map);
L.marker([0, 0]).addTo(map);
L.marker([0, 0]).addTo(map);

var header = ['lat','lng','label'];
var TempArr = [[39.952238, -75.201702,'Top1'],[39.952927, -75.217711,'Top2'],[39.944143, -75.174881,'Top3']];
TempArr.unshift(header);
for (i=0; i < TempArr.length; i++){console.log(TempArr[i])};
var makeAMarker = (obj) => {return L.marker([obj[0], obj[1]]).bindPopup(obj[2])}
for (var i=1; i <= TempArr.length; i++){ makeAMarker(TempArr[i]).addTo(map) }


/* =====================

End code

===================== */

</script>
</body>
</html>
98 changes: 98 additions & 0 deletions lab/lab1/js/part2(try).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* =====================
# Lab 1, Part 2 — Function Review
===================== */

/* =====================
Instructions: "Write a function that adds one to the number provided"
Example: "plusOne(2) should return 3"
===================== */

var plusOne = function(num) {
return num + 1;
};

console.log('plusOne success:', plusOne(99) === 100);

/* =====================
Instructions: "Write a function that adds two to the number provided"
Example: "plusTwo(2) should return 3"
NOTE: Try using the `plusOne` function in the body of your `plusTwo` function
===================== */

var plusTwo = function(num) {
return num + 2;
};

console.log('plusTwo success:', plusTwo(99) === 101);


/* =====================
Instructions: "Write a function that checks to see if a number is an integer,
if so, it returns even or odd depending on the number, otherwise it returns "error"

===================== */

var oddOrEven = function(num) {

};

console.log('oddOrEven success:', oddOrEven(100) === 'even' && oddOrEven(201) === 'odd');



/* =====================
Instructions: "Write a function, age, that takes a birth year and returns an age in years."
(Let's just assume this person was born January 1 at 12:01 AM)
Example: "age(2000) should return 17"
===================== */

var age = function(num) {
return 2019 - num;
};

console.log('age success:', age(1971) === 48);

/* =====================
Instructions: "Write a function that returns true for numbers over 9000 and false otherwise"
Example: "over9000(22) should return false"
===================== */

var over9000 = function(num) {
if (num>9000){
return 'true';
} else {
return 'false';
}
};

console.log('over9000 success:', over9000(9001) === true && over9000(12) === false);


/* =====================
Instructions: "Write a function, trump, that checks to see if the input is a string
and if it is, returns the text in all upper case
and if it is not, it prints to the console, "TRY WITH STRINGS"
===================== */


var trump = function(text) {
if(typeof text === string){
text.toUpperCase();
} else {
console.log('TRY WITH STRINGS');
}
};

console.log('trump success:', trump(12) === "TRY WITH STRINGS" && trump('hi') === 'HI');



/* =====================
Instructions: "Write a function which returns the y coordinate of a line given m, x, and b"
Example: "y(0, 0, 0) should return 0; y(1, 1, 1) should return 2"
===================== */


var y = function(m,x,b) {};

console.log('y success:', y(12, 1, 12) === 24);
File renamed without changes.
12 changes: 6 additions & 6 deletions lab/lab1/part1-types-variables-math.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

===================== */

var a;
var a = 31;
var resultTask1 = (a > 30);

var b;
var b = 'This is b';
var resultTask2 = (typeof b == 'string');

var c;
var c = 5;
var resultTask3 = (c ** 2 == 25)
var d;

var d = 10;
var resultTask4 = (d == 'cassiopeia'.length);

var e;
var e = 18;
var resultTask5 = (e%5 == 3);

/* =====================
Expand Down
2 changes: 1 addition & 1 deletion lab/lab1/part2-function-review.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</head>
<body>
<!-- Javascript Imports -->
<script src="part2.js"></script>
<script src="js/part2.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion lab/lab2/part1-functions-are-values.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

/* Define your function here */

for (var i = 0; i < theArray.length, i++) { /* Inside the loop*/ }
for (var i = 0; i < theArray.length; i++) { /* Inside the loop*/ }

/* =====================

Expand Down