-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackEnd.js
More file actions
62 lines (59 loc) · 2.03 KB
/
Copy pathbackEnd.js
File metadata and controls
62 lines (59 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var map, marker;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 31.9686, lng: -99.9018},
zoom: 5
});
var input = document.getElementById('search');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
marker = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});
document.getElementById('search-btn').addEventListener('click', function() {
marker.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
window.alert("No details available for input: '" + place.name + "'");
return;
}
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(15);
}
marker.setPosition(place.geometry.location);
marker.setVisible(true);
});
}
const searchBar = document.getElementById("search-bar");
const searchBtn = document.getElementById("search-btn");
const scoreBox = document.getElementById("score-box");
fetch("cities.txt")
.then(response => response.text())
.then(data => {
// Split the text file by newline
const lines = data.split("\n");
// Create an object to store the city-number pairs
const cityScores = {};
// Loop through each line and add the city-number pairs to the object
lines.forEach(line => {
const [city, state, country, score] = line.split(",");
cityScores[city + ", " + state + ", " + country + ":"] = score;;
});
// Listen for the click event on the search button
searchBtn.addEventListener("click", e => {
const city = searchBar.value;
scoreBox.value = "hi";
// Check if the city exists in the cityScores object
if (cityScores[city]) {
// If it does, update the score text box with the corresponding number
scoreBox.value = cityScores[city];
} else {
// If it doesn't, clear the score text box
scoreBox.value += " bye";
}
});
});