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

Homework 4 submission for Dylan Graham #3

Open
wants to merge 2 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
16 changes: 8 additions & 8 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Project Name: Blank Template
Client: Your Client
Author: Your Name
Project Name: Citipix
Client: FEWD
Author: Dylan Graham
Developer @GA in NYC
*/

Expand Down Expand Up @@ -124,19 +124,19 @@ header {
}

.nyc {
background-image: url(../images/nyc.jpg)
background-image: url(../images/nyc.jpg);
}
.sf {
background-image: url(../images/sf.jpg)
background-image: url(../images/sf.jpg);
}
.la {
background-image: url(../images/la.jpg)
background-image: url(../images/la.jpg);
}
.austin {
background-image: url(../images/austin.jpg)
background-image: url(../images/austin.jpg);
}
.sydney {
background-image: url(../images/sydney.jpg)
background-image: url(../images/sydney.jpg);
}

/******************************************
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ <h1>CitiPix</h1>
</div>

<script src="js/jquery-2.1.4.js"></script>
<script src="js/app.js"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$(function () {

// Listen for click
$("#submit-btn").click(searchForCity);

// Searches given input
function searchForCity() {
// Get the input from the search bar
var city = $("#city-type").val();
console.log("City: ", city);
getCityPic(city);
}

// Helper function
function getCityPic(searchInput) {
var cleanedSearchInput = searchInput.trim().toLowerCase();
console.log("seach: ", searchInput);
console.log("clean: ", cleanedSearchInput);
// "New York" or "New York City" or "NYC" make the background of the page nyc.jpg
if (cleanedSearchInput === "new york" || cleanedSearchInput === "new york city" || cleanedSearchInput === "nyc") {
$("body").attr('class', 'nyc');
}
// "San Francisco" or "SF" or "Bay Area" make the background of the page sf.jpg
else if (cleanedSearchInput === "san francisco" || cleanedSearchInput === "sf" || cleanedSearchInput === "bay area") {
$("body").attr('class', 'sf');
}
// "Los Angeles" or "LA" or "LAX" make the background of the page la.jpg
else if (cleanedSearchInput === "los angeles" || cleanedSearchInput === "la" || cleanedSearchInput === "lax") {
$("body").attr('class', 'la');
}
// "Austin" or "ATX" make the background of the page austin.jpg
else if (cleanedSearchInput === "austin" || cleanedSearchInput === "atx") {
$("body").attr('class', 'austin');
}
// "Sydney" or "SYD" make the background of the page sydney.jpg
else if (cleanedSearchInput === "sydney" || cleanedSearchInput === "syd") {
$("body").attr('class', 'sydney');
}
// If no match, give an alert, remove background image, and clear the input
else {
alert("Sorry, we don't recognize input: " + searchInput + "\n Try again");
Copy link

Choose a reason for hiding this comment

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

@dylantg nice to have an error message 💯

$("body").removeAttr('class');
clearInput();
}
}

function clearInput() {
$("#city-type").val("");
Copy link

Choose a reason for hiding this comment

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

@dylantg if you use toLowerCase() it willl cover if the input was entered with a upper case.

Copy link
Author

Choose a reason for hiding this comment

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

I have var cleanedSearchInput = searchInput.trim().toLowerCase(); on Line 16 to allow for various inputs.

Copy link

Choose a reason for hiding this comment

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

@dylantg apologies

}

});