# Can't get background color to change with Random Quote API

**URL:** <https://forum.freecodecamp.org/t/cant-get-background-color-to-change-with-random-quote-api/84903>\
**Category:** General\
**Created:** [February 7, 2017, 8:17pm UTC](https://forum.freecodecamp.org/t/cant-get-background-color-to-change-with-random-quote-api/84903 "2017-02-07T20:17:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidakoch](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@davidakoch](https://forum.freecodecamp.org/u/davidakoch)\
**Post date:** [February 7, 2017, 8:17pm UTC](https://forum.freecodecamp.org/t/cant-get-background-color-to-change-with-random-quote-api/84903/1 "2017-02-07T20:17:13Z")

</div>

So i watched Stephen Mayeux’s online video on creating a random quote api. I used it for my own. It was very useful. However, I looked at freecodecamp’s example in codepen and wanted to replicate the background color changing when you click the quote button. I thought I knew enough to make it work even though Stephen doesn’t cover it in his video. However, mine is now working. Some help is appreciated. Thanks:

below is my jQuery code:

```javascript
   var quote; 

  var colors = ['#16a085', '#27ae60', '#2c3e50', '#f39c12', '#e74c3c', 
  '#9b59b6', '#FB6964', '#342224', "#472E32", "#BDBB99", "#77B1A9", 
  "#73A857"];

  function getNewQuote() {
	$.ajax({
		url: 'http://api.forismatic.com/api/1.0/', 
		jsonp: 'jsonp',
		dataType: 'jsonp',
		data: {
			method: 'getQuote',
			lang: 'en',
			format: 'jsonp'
		},

		success: function(response){
			quote = response.quoteText;
			author = response.quoteAuthor; 
			$('#quote-text').text(quote);
			if(author){
				$('#quote-author').text('-- ' + author);
			} else {
				$('#quote-author').text('-- unknown');
			}

		var color = Math.floor(Math.random() * colors.length);
	    	$('body').animate({
	        backgroundColor: colors[color],
	    	}, 1000);
     	} 
	});
  }
	
  $(document).ready(function() {
	getNewQuote();
	$('#quote-button').on('click', function(event) {
		event.preventDefault();
		getNewQuote();
		
	});

	$('#twitter-button').on('click', function(event){
		event.preventDefault();
		window.open('https://www.twitter.com/intent/tweet?text=' + encodeURIComponent(quote + '-- ' + author));
	} )
  });

```

---

<div class="post-metadata">

**Author:** ![gskll](https://avatars.discourse-cdn.com/v4/letter/g/8edcca/32.png) [@gskll](https://forum.freecodecamp.org/u/gskll)\
**Post date:** [February 7, 2017, 9:35pm UTC](https://forum.freecodecamp.org/t/cant-get-background-color-to-change-with-random-quote-api/84903/2 "2017-02-07T21:35:38Z")

</div>

Hey,

You can’t animate the background colour with jQuery, it only really animates properties that have a numeric value. Check the docs for more info.

You can set the background with another method though, and then animate the opacity to get the effect you’re looking for!

Hope that helps

ps [http://api.jquery.com/animate/](http://api.jquery.com/animate/)

---

<div class="post-metadata">

**Author:** ![przemoo83](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@przemoo83](https://forum.freecodecamp.org/u/przemoo83)\
**Post date:** [February 7, 2017, 9:39pm UTC](https://forum.freecodecamp.org/t/cant-get-background-color-to-change-with-random-quote-api/84903/3 "2017-02-07T21:39:47Z")

</div>

Yes **@gskll** is right.You cannot do it with jQuery only. Alternatively you can add jQuery UI library and your code should work without any changes

---

<div class="post-metadata">

**Author:** ![davidakoch](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@davidakoch](https://forum.freecodecamp.org/u/davidakoch)\
**Post date:** [February 8, 2017, 2:30am UTC](https://forum.freecodecamp.org/t/cant-get-background-color-to-change-with-random-quote-api/84903/4 "2017-02-08T02:30:41Z")

</div>

Thank you for your help. I review the documentation.

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [February 8, 2017, 3:15am UTC](https://forum.freecodecamp.org/t/cant-get-background-color-to-change-with-random-quote-api/84903/5 "2017-02-08T03:15:58Z")

</div>

I cleaned up your code.  
You need to use triple backticks to post code to the forum.  
See [this post for details](http://forum.freecodecamp.com/t/forum-code-formatting/25574).

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:24pm UTC](https://forum.freecodecamp.org/t/cant-get-background-color-to-change-with-random-quote-api/84903/6 "2021-01-16T17:24:53Z")

</div>

Closed on January 16, 2021, 5:24pm UTC


