1

I trying to learn how to program using node.js and javascript, one the assignment for my class is to create a javascript file that generate random number.

these are the instructions of the assignment. Can somebody explain me how can I start this problem, how can I print color in the console, or how to create a js file that outputs a html document.

Create a file named randoms.js that outputs an HTML document that lists 10 random colors. The generated document should look like the following except the hexadecimal color values should be random. Each time you run the program, it should generate 10 different colors values

<html>
  <head>
    <meta charset="UTF-8">
    <title>Ten Random Colors</title>
  </head>
  <body>
    <ul>
      <li style="color: #ae3d04">ae3d04</li>
      <li style="color: #ce8cfc">ce8cfc</li>
      <li style="color: #510f40">510f40</li>
      <li style="color: #a256c6">a256c6</li>
      <li style="color: #d85fd1">d85fd1</li>

      ... 10 list items in total

    </ul>
  </body>
</html>

Each time you run the program it should generate a different set of color values.

Send the output to the console by calling console.log. You can view the HTML document that you generate by redirecting standard output to a file as follows.

Pedro
  • 1,440
  • 2
  • 15
  • 36
  • It's normally a good idea to give us some sort of indication as to how you think you should tackle a problem. This gives us some idea as to where to start helping you. – ocajian Jan 14 '15 at 07:15
  • possible duplicate of [Random Color generator in Javascript](http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript) – kumarharsh Jan 14 '15 at 07:19

1 Answers1

3

see this , http://jsfiddle.net/uwh4ksct/

$(function(){
    $("li").each(function(i,e){
        var t=getRandomColor();
     $(e).css("color",t);
        console.log(t);

    })

});

   function getRandomColor() {
    var letters = '0123456789ABCDEF'.split('');
    var color = '#';
    for (var i = 0; i < 6; i++ ) {
        color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
}  

this will generate new random colors each time you refresh page

Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
  • @Pedro: don't worry. Naeem will be available for free even with you will try to make a living as a programmer, writing your code for you for free as you need. Or may be not. – 6502 Jan 14 '15 at 07:23
  • It seems to me that most often there is green (even 4 times in one series (50x refresh)), an interesting coincidence. – Mardzis Jan 14 '15 at 07:28
  • @Pedro.. I will not be available for free.. its just that right now I am free.. lol: – Naeem Shaikh Jan 14 '15 at 07:30