Created
December 21, 2020 13:52
-
-
Save BrianJenney/2bebee57254433820c7b1d4f5674c713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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