Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="container">
  <h1> The Random Quote Machine </h1>

  <div id="quotebox">
    <p id="quote">"A wizard is never late, nor is he early, he arrives precisely when he means to."</p>
    <p id="quoteinfo"><span id="character">Gandalf</span><span id="movie">The Lord of the Rings: The Fellowship of the Ring</span></p>

  </div>
  <!-- end quotebox div -->

  <div id="buttons">
    <div id="newquote">New Quote<i id="quoteicon" class="fas fa-comment-alt"></i></div>
    <div id="tweetlink"><i id="twittericon" class="fab fa-twitter"></i></div>
  </div> <!-- end button div -->
</div> <!-- end container div -->
              
            
!

CSS

              
                * { 
/* styles to make borders not take on extra space */ 
	-moz-box-sizing: border-box; 
	-webkit-box-sizing: border-box; 
	box-sizing: border-box; 
} 

html { 
  width: 100%;
	height: 100%;
} 

body{ 
  width: 100%;
	height: 100%;
	background: url(http://res.cloudinary.com/dlyons/image/upload/v1525981944/theaterseats-min.jpg);
	background-size: cover;
	background-position: center;
} 

/* Browser style reset so they all play nice */ html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, time, mark, audio, video { 
	font-size: 100%; 
	margin: 0; 
	padding: 0; 
	outline: 0 none; 
	vertical-align: baseline; 
}

#container{
	display: flex;
	flex-direction: column;
	width: 100%;
	max-width: 1150px;
	margin: 0 auto;
	padding: 0 4%;
  text-align: center;
}

h1{
  margin: 3.13vw 0;
	color: #ffb60a;
	font-family: 'Limelight';
	font-size: 3.5em;
	font-weight: 500;	
}

#quotebox{
  height: 400px;
  padding: 6.25vw;
	background: rgba(0, 0, 0, 0.7);
	border: 2px dotted #ffb60a;
	border-radius: 10px;
	transition: height 2s;
}

#quote, #quoteinfo{
	color: #ffffff;
	font-family: 'Comfortaa';
}

#quotebox #quote{
	text-align: left;
	font-size: 180%;
	font-weight: 400;
}

#quotebox #quoteinfo{
	margin: 2% 0;
  text-align: right;
}

#character{
  margin: 0 2% 0 0;
	font-weight: bold;
	font-size: 24px;	
}

#movie{
	font-size: 18px;
	font-style: italic;
}

#buttons{
	display: flex;
	justify-content: flex-end;
}

#newquote{
	width: 100%;
	max-width: 200px;
	min-height: 50px;
	margin-top: 1.25vw;
	padding: 15px;
  align-self: flex-end;
	background: #ffb60a;
	color: #000000;
	font-family: 'Comfortaa';
	font-size: 18px;
	font-weight: 700;
	cursor: pointer;
	border-radius: 5px;
	-webkit-text-stroke: .15px;
}

#quoteicon{
	margin-left: 5%;
}

#quoteicon, #twittericon{
	vertical-align: middle;
}

#tweetlink{
	display: block;
	width: 100%;
	max-width: 75px;
	min-height: 50px;
	margin: 1.25vw 0 0 1.25vw;
	padding: 15px;
  align-self: flex-end;
	background: #1DA1F3;
	color: #ffffff;
	font-size: 18px;
	cursor: pointer;
	border-radius: 5px;
}

/* ========== Mobile Styles ========== */

@media only screen and (max-width: 728px){

	#quotebox{
		height: 375px;
	}

	#quotebox #quote {
    font-size: 150%;
	}
  
	#character{
		font-size: 115%;
	}
  
	#movie{
		display: block;
		font-size: 85%;
	}
}

@media only screen and (max-width: 450px){

	#quotebox {
    	height: 350px;
	}
  
	h1{
		font-size: 2em;
	}
  
	#quotebox #quote {
    	font-size: 120%;
	}
  
	#quotebox #quoteinfo{
		margin: 4.25vw 0;
    text-align: left;
	}
  
	#character{
		font-size: 115%;
	}
  
	#movie{
		display: block;
		font-size: 85%;
	}

	#buttons {
		margin-top: 5vw;
    	justify-content: center;
	}
}
              
            
!

JS

              
                // object of quotes

const quotes = {

	1 : {
		quote : "A wizard is never late, nor is he early, he arrives precisely when he means to.",
		character : "Gandalf",
		movie : "The Lord of the Rings: The Fellowship of the Ring"
	},

	2 : {
		quote : "Cage goes in the water, you go in the water. Shark's in the water. Our shark.",
		character : "Quint",
		movie : "Jaws"
	},

	3 : {
		quote : "By Grabthar's hammer...what a savings.",
		character : "Alexander Dane",
		movie : "Galaxy Quest"
	},

	4: {
		quote : "Somebody in this camp ain't what he appears to be. Right now that may be one or two of us. By Spring, it could be all of us.",
		character : "MacReady",
		movie : "John Carpenter's The Thing"
	},

	5: {
		quote : "Wendy? Darling? Light, of my life. I'm not gonna hurt ya. You didn't let me finish my sentence. I said, I'm not gonna hurt ya. I'm just going to bash your brains in!",
		character : "Jack Torrance",
		movie : "The Shining"
	},

	6 : {
		quote : "I think that I am familiar with the fact that you are going to ignore this particular problem until it swims up and BITES YOU ON THE ASS!",
		character : "Hooper",
		movie : "Jaws"
	},

	7 : {
		quote : "HEY! Don't open that! It's an alien planet! Is there air? You don't know! ",
		character : "Guy Fleegman",
		movie : "Galaxy Quest"
	},

	8: {
		quote : "It's good to meet you, Dr. Banner. Your work on anti-electron collisions is unparalleled. And I'm a huge fan of the way you lose control and turn into an enormous green rage monster.",
		character : "Tony Stark", 
		movie : "Avengers"
	},

	9 : {
		quote : "You met me at a very strange time in my life",
		character : "Narrator",
		movie : "Fight Club"
	},

	10: {
		quote : "Where is the horse and the rider? Where is the horn that was blowing? They have passed like rain on the mountain, like wind in the meadow. The days have gone down in the West behind the hills into shadow. How did it come to this?",
		character : "Theoden",
		movie : "The Lord of the Rings: The Two Towers"
	},

	11 : {
		quote : "If my calculations are correct, when this baby hits 88 miles per hour... you're gonna see some serious shit.",
		character : "Dr. Emmett Brown",
		movie : "Back to the Future"
	},

	12 : {
		quote : "Ray, when someone asks you if you're a god, you say, \"YES!\"",
		character : "Winston Zeddemore",
		movie : "Ghostbusters"
	},

	13 : {
		quote : "Why worry? Each one of us is carrying an unlicensed nuclear accelerator on his back.",
		character : "Dr. Peter Venkman",
		movie : "Ghostbusters"
	},

	14 : {
		quote : "Good evening, Clarice",
		character : "Hannibal Lecter",
		movie : "Silence of the Lambs"
	},

	15 : {
		quote : "After that my guess is that you'll never hear from him again. The greatest trick the devil ever pulled was convincing the world he didn't exist. And like that...he's gone.",
		character : "Verbal",
		movie : "The Usual Suspects"
	},

	16 : {
		quote : "Size matters not. Look at me. Judge me by my size, do you? Hmm? Hmm. And well you should not. For my ally is the Force, and a powerful ally it is.",
		character : "Yoda",
		movie : "Star Wars: The Empire Strikes Back"
	},

	17 : {
		quote : "That's it, man. Game over, man. Game over!",
		character : "Private Hudson",
		movie : "Aliens"
	},

	18 : {
		quote : "We'd better get back 'cause it'll be dark soon and they mostly come at night. Mostly.",
		character : "Newt",
		movie : "Aliens"
	},

	19 : {
		quote : "Mawwiage. Mawwiage is wat bwings us togeder today. Mawwiage, that bwessed awwangement, that dweam wifin a dream… And wuv, twue wuv, will fowwow you foweva… So tweasure your wuv— ",
		character : "The Impressive Clergyman",
		movie : "The Princess Bride"
	},

	20 : {
		quote : "Every man dies, not every man really lives.",
		character : "William Wallace",
		movie : "Braveheart"
	},

	21 : {
		quote : "Are you saying that I put an abnormal brain into a seven and a half foot long, fifty-four inch wide GORILLA?",
		charater : "Dr. Frederick Fronkensteen",
		movie : "Young Frankenstein"
	},

	22 : {
		quote : "Vee had better confeerm de fect dat Yunk Frankenshtein iss indeed VALLOWING EEN EES GANDFADDA'S VOOTSHTAPS",
		character : "Inspector Kemp",
		movie : "Young Frankenstein"
	},

	23 : {
		quote : "The unknown future rolls toward us. I face it, for the first time, with a sense of hope. Because if a machine, a Terminator, can learn the value of human life, maybe we can too.",
		character : "Sarah Connor",
		movie : "Terminator 2"
	},

	24 : {
		quote : "Nicholas Angel: Are there any questions?\n\nDanny Butterman: Is it true that there's a point on a man's head where if you shoot it, it will blow up?",
		movie : "Hot Fuzz"
	},

	25 : {
		quote : "Dr. Richard Kimble: I didn't kill my wife!\n\nDeputy Marshal Samuel Gerard: I don't care!",
		movie : "The Fugitive"
	},

	26 : {
		quote : "As Mr. Sloan always says, there is no \"I\" in team, but there is an \"I\" in pie. And there's an \"I\" in meat pie. Anagram of meat is team... I don't know what he's talking about.",
		character : "Shaun",
		movie : "Shaun of the Dead"
	},

	27 : {
		quote : "Dr. Rumack: Can you fly this plane, and land it?\n\nTed Striker: Surely you can't be serious.\n\nDr. Rumack: I am serious... and don't call me Shirley.",
		movie : "Airplane!"
	},

	28 : {
		quote : "I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time... like tears in rain... Time to die.",
		character : "Batty",
		movie : "Blade Runner"
	},

	29 : {
		quote : "John Hammond: All major theme parks have delays. When they opened Disneyland in 1956, nothing worked!\n\nDr. Ian Malcolm: Yeah, but, John, if The Pirates of the Caribbean breaks down, the pirates don't eat the tourists.",
		movie : "Jurassic Park"
	},

	30 : {
		quote : "Your scientists were so preoccupied with whether they could, they didn’t stop to think if they should.",
		character : "Dr. Ian Malcolm",
		movie : "Jurassic Park"
	},
  
  31 : {
    quote : "Hail to the king, baby.",
    character : "Ash Williams",
    movie : "Army of Darkness"
  }

};

// HTML elements in the DOM
let quoteDisplay = document.getElementById("quote");
let characterDisplay = document.getElementById("character");
let movieDisplay = document.getElementById("movie");
let quoteButton = document.getElementById("newquote");
let tweetButton = document.getElementById("tweetquote");
let tweetLink = document.getElementById("tweetlink");

// first get the max number of quotes
 let quoteLength = 0;
    for (let quote in quotes){
      quoteLength ++;
    }

// create holder variables
let oldNum;
let currentNum;
let nextNum;
let formattedQuote;

function getQuote(){
  let min = Math.ceil(1);
  let max = Math.floor(quoteLength);
  nextNum = Math.floor(Math.random() * (max - min + 1)) + min;
  oldNum = currentNum;
  currentNum = nextNum;

  // update the HTML elements, check for \n in quotes with multiple characters talking
  urlFormattedQuote = quotes[nextNum].quote.replace(new RegExp('\n','g'), '%0A'); 
  let machineURL = '<a href="#">The Random Quote Machine!</a>'
  quoteDisplay.innerHTML = quotes[nextNum].quote.replace(new RegExp('\r?\n','g'), '<br />');
  characterDisplay.textContent = quotes[nextNum].character;
  movieDisplay.textContent = quotes[nextNum].movie;

// check if the previous number matches the new one, if it does, run the generator again
    if (nextNum === oldNum){
      getQuote();
    }
}

// run generator function on initial page load
getQuote();


// run generator function on button click
quoteButton.addEventListener("click", function(){
  getQuote();
});

// tweet quote on button click
tweetLink.addEventListener("click", function(){

	// check to see if character is undefined (conversation quotes)
	if(quotes[nextNum].character == undefined){
		quotes[nextNum].character = " ";
	}

	// open the twitter form in a popup window
	window.open("https://twitter.com/intent/tweet?text=" + urlFormattedQuote + " -" + quotes[nextNum].character + " (" + quotes[nextNum].movie + ")","", "width=450,height=500,resizable");
});
              
            
!
999px

Console