Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialbenyoungblood
10,062 PointsCannot target my first index.
Hey guys, I'm having an issue randomizing a theme on my portfolio website. When you click a button, changeTheme() function is called and should select a random theme from the themeArr array. I see that my math.random function is handing out a random sequence of 0 or 1 and even if i specifically state that I want themeArr[0] to be used, it is using themeArr[1]
const changeTheme = () => {
let randIndex = Math.floor(Math.random() * 2);
const themeArr = [
{
theme: {
bodyBG: body.style.backgroundColor = 'black',
fontColor: mainWrapper.style.color = 'white',
navBG: mainNav.style.backgroundColor = 'white',
navFont: mainNav.style.color = 'black',
imageBG: profImg.style.backgroundColor = 'white',
buttonColor: themeButton.style.backgroundColor = 'white',
buttonFont: themeButton.style.color = 'black'
}
},
{
theme: {
bodyBG: body.style.backgroundColor = 'lightgray',
fontColor: mainWrapper.style.color = 'brown',
navBG: mainNav.style.backgroundColor = 'lightgray',
navFont: mainNav.style.color = 'brown',
imageBG: profImg.style.backgroundColor = 'lightgray',
buttonColor: themeButton.style.backgroundColor = 'lightgray',
buttonFont: themeButton.style.color = 'brown'
}
}
]
return themeArr[randIndex];
}