css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container text-center">
  <div class="quote">    
    <blockquote class="blockquote">
      <p id="text"></p>
      <footer class="blockquote-footer" id="author"></footer>
  </blockquote>
  </div>
  <div class="randomshare" style="font-size:22px;">
    <a class="btn" href="#" target="_blank" id="twitter">
       <i class="fa fa-twitter"></i>
    </a>
    <button id="getMessage" class="btn" onclick="changeColor();">New quote</button>
</div>
</div>
<div class=" footer text-center "><a href="http://www.ivanilievski.com/" target="_blank">by Ivan</a></div>




<!--jQuery-->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
            
          
!
            
              body{
  background-color: #006699;
  heigth: 100vh;
}
.container{
  margin: auto;
  width: 50%;
  border-radius: 30px;
  padding: 30px;
  margin-top: 100px;
  background-color:#ffffff;
}
.footer{
  margin: auto;
  width: 50%;
  padding: 2px;
}

.footer a{
  color: #ffffff;
}

button{
  color: #ffffff;
}
button:hover{
  color:#ffffff;  
}

.btn{
  background-color: #006699;
  align="right";
}

a, fa-twitter{
  color: #ffffff;
}

a, fa-twitter:hover{
  color: #ffffff !important;
}

.blockquote, .blockquote-footer{
  color: #006699;
}
            
          
!
            
              //Selecting button variables so i can perform clicking
var button = document.getElementById("getMessage");
var tweet = document.getElementById("twitter");
var tweetString = '';
var tweetAuthor = '';

/* This function chooses random color from array of colors and then sets the color to all html element that need to change color */
function changeColor(){
  var colors = ["#1abc9c", "#2ecc71", "#3498db", "#9b59b6", "#34495e", "#16a085", "#27ae60", "#2980b9", "#8e44ad", "#2c3e50", "#f1c40f", "#e67e22", "#e74c3c", "#f39c12", "#d35400", "#c0392b"];

var randomNumber = Math.floor(Math.random()*colors.length);
var randomColor = colors[randomNumber];
  document.getElementById("")
   document.body.style.background = randomColor;
   document.getElementById("text").style.color = randomColor;
   document.getElementById("author").style.color = 
     randomColor;   document.getElementById("getMessage").style.background=
     randomColor;
  document.getElementById("twitter").style.background =   randomColor;
}


/*
Making function that makes AJAX request
*/
function ajaxCall(){
  
  var requestData = new XMLHttpRequest();
  
  requestData.open('GET', 'https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=16');
  requestData.onload = function(){
    
    if(requestData.status >= 200 && requestData.status <= 400){
      
      var useData = JSON.parse(requestData.responseText);
      console.log(useData);
      renderHTML(useData);
      
    } else {
      
      console.log('The serever connection is accomplished, but there is some problem with data');
      
    }
       
  };
  
  requestData.onerror = function(){
    console.log("Connection Error!");
  }
  
  requestData.send();
  
};

// very first ajax call, when web site is just loaded
ajaxCall();

button.addEventListener("click", function(){
  
  //ajax call when the button is clicked
  ajaxCall();
  
});


//setting up data to proper html elements
function renderHTML(data){
  
  var randomNumber = Math.floor(Math.random()*16);
  
  var htmlQuote = data[randomNumber].content;
  var htmlAuthor = data[randomNumber].title;
  tweetAuthor = htmlAuthor;
  newS = htmlQuote.substring(3,htmlQuote.length-5);
  console.log(newS);
  tweetString = newS;
  // console.log(data[randomNumber].content);
  // console.log(data[randomNumber].title);
  
  document.getElementById("text").innerHTML = newS;
  document.getElementById("author").innerHTML = htmlAuthor;
  
}


//This is tweet button
tweet.addEventListener('click', function(){
  var tweetURL = 'https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=' + encodeURIComponent('"' + tweetString + '" ' + ' by ' + tweetAuthor);
  window.open(tweetURL);
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console