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 trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops The Refactor Challenge Solution

Why div print colors instead of numbers?

I was wondering, why would the div print color as a hexadecimal, instead of just number. Cool trick on how to make div colorful, but i am lost.

2 Answers

Jeff Pierce
Jeff Pierce
18,077 Points

Hi Ammar,

You can specify colors in multiple ways. Hex does seem to be the most common. They can be specified by name: http://jdstiles.com/colorchart.html

Or by Hex, RGB, and HSB http://www.rapidtables.com/web/color/RGB_Color.htm

Wikipedia has a good article on web colors: https://en.wikipedia.org/wiki/Web_colors

Not a Hex value, but rather an RBG value. the random numbers are being applied as RGB values and then being inputted as an RGB background color for each div in the loop. It's one of many really cool ways you can use Math.random() to manipulate number values in JS.