Skip to content

Instantly share code, notes, and snippets.

@BrianJenney
Created December 21, 2020 13:52
Show Gist options
  • Save BrianJenney/2bebee57254433820c7b1d4f5674c713 to your computer and use it in GitHub Desktop.
Save BrianJenney/2bebee57254433820c7b1d4f5674c713 to your computer and use it in GitHub Desktop.
/* logic for determing a button color based on the page location: */
// using conditional logic
const location = window.location.pathname;
let buttonColor = 'red';
if(location === 'signIn'){
buttonColor = 'yellow';
}else if(location === 'signOut'){
buttonColor = 'orange';
}else if(location === 'shop'){
buttonColor = 'green';
}
// using an object
const location = window.location.pathname;
const buttonColorMap = {
signIn: 'yellow',
signOut: 'orange',
shop: 'green'
}
const buttonColor = buttonColorMap[location] || 'red';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment