Color flipper project

Hello, so i’m gaining experience through courses and building projects. I checked my instructors work and mine and it’s the same yet when I click on the button to change the background nothing happens!

1 Like

Please don’t share pictures of code. Please either cut and paste code or share a link to a repo or an online IDE.

That being said, line 14 doesn’t look right to me.

Ok thanks but i rechecked it and nothing seems wrong. It’s straight from codebubb youtube channel.

@kevinSmith is right of course. Open the console in your browser’s dev tools and type the following:

Math.random() = 10;

See what you get.

Math.random() = 10 in the console says I can’t assign the number to the function.

I don’t see why it wouldn’t be tied to my hexvalues.length since it’s just randomly generating from the array I set up in the hexValues expression.

Your random number generator will be tied to hexvalues.length, you just aren’t doing it properly. I think you should google on how to generate a random number within a specific range using JS. Once you understand that then you will figure out how to change that line.

But as you discovered, you definitely can’t set Math.random() to a number.

Ok. Thank you. Will do.

I just thought that’s what math.floor() was for. I’ll check out the syntax.

You’re almost there, you just have a typo, I think. Think about what this code is doing. What does Math.random return? How do we convert that into a random number in a range? As @bbsmooth suggested, a google search will reveal a lot of information on generating random numbers in JS. That is what professional developers do when they aren’t sure about something - they google it.


Using floor has nothing to do with it being impossible to set the function call equal to a number.

Ok. Thanks. Thanks for the smack over my head haha (metaphorically).

We’ve all been there. Just keep learning, you’ll get there.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.