-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"); | ||
$("body").removeAttr('class'); | ||
clearInput(); | ||
} | ||
} | ||
|
||
function clearInput() { | ||
$("#city-type").val(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dylantg if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dylantg apologies |
||
} | ||
|
||
}); |
There was a problem hiding this comment.
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 💯