Help on Random Quote Machine

have done to this point, need help further ;

See the Pen Random Quote by Eldar (@eldarm) on CodePen.

Instead of .append() you can use .html() to change the whole content of the selected element. This way you don’t keep adding quotes, but you replace them. Of course you can’t do this on the body because it would also remove the button, so you neeed to add some kind of container element in which you can place the quotes.

But maybe you can be more specific as to what you want to accomplish?

1 Like

I have changed code as you said upside, I aim to change color of css(background) when clicked on button, so they should be one click, and different quote and different color.

One way to do this would be to create a variable which holds a random rgb value:

var color = "rgb(" + Math.floor(Math.random()*255) + "," + Math.floor(Math.random()*255) + "," + Math.floor(Math.random()*255) + ")";  

And then instead "rgb(255, 51, 51)" use the color variable.

One problem with this is that your text becomes unreadable when you have a dark color.

1 Like

You are true genius!)… I just changed first 255 number to 250 wish black in this number will differ from times shrift black color, so it could be readable)…Thanx)

Could you look at my code, I added new div to change also whole background of window, but is not working… could give some advice ,
thanks ahead

function(a) {
  $("#paragraph")
    .html(a[0].content + "<p>&mdash; " + a[0].title + "</p>")
    .css("background-color", color); 
  $("#whole-body")
    .css("background-color", color);
 }

Instead of:

function(a) {
  $("#paragraph")
    .html(a[0].content + "<p>&mdash; " + a[0].title + "</p>")
    .css("background-color", color); 
}
$("#whole-body")
  .css("background-color", color);
1 Like

Thank you @BenGitter , you helped me a lot