HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs 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 its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!-- Notice how we have used "semantic HTML" here -->
<!-- Re-read the lesson if you don't understand what that means -->
<!-- https://www.zachgollwitzer.com/posts/2021/fullstack-developer-series/7-html-crash-course-->
<main>
<section class="content">
<!-- Your HTML code goes here -->
</section>
<!-- No need to change anything in this section -->
<section class="sidebar">
<h2>Actions</h2>
<button onclick="showMeme()">Show a Meme</button>
<button onclick="showJoke()">Tell Me a Joke</button>
<button onclick="showQuote()">Random Quote</button>
<button onclick="showRiddle()">Riddle me</button>
<button class="reveal-btn" onclick="revealAnswers()">Reveal Riddle Answer</button>
<p class="attribution">Code challenge by <a href="https://www.twitter.com/zg_dev" target="_top">@zg_dev</a></p>
</section>
</main>
/*
NO ACTION REQUIRED BY YOU
Don't worry about this section. These CSS styles are here to make the HTML document look cleaner, but are not part of the lesson.
Just write your HTML however you want and these will automatically work.
*/
body {
background-color: #1D2326;
color: #BFA38A;
font-family: monospace;
}
main {
display: flex;
flex-direction: row;
}
img {
border: 1px solid white;
border-radius: 5px;
max-width: 350px;
width: 100%;
}
p {
color: #8097A6;
}
.attribution {
position: absolute;
right: 20px;
bottom: 20px;
font-size: 0.8rem;
background-color: #8097A6;
padding: 10px;
border-radius: 5px;
color: #1D2326;
box-shadow: 1px 2px 5px 1px rgba(255,255,255, 0.2);
}
a {
color: white;
}
a:hover {
opacity: 0.8;
}
.content {
width: 65%;
padding-left: 30px;
padding-right: 20px;
}
.content p {
max-width: 80%;
}
.sidebar {
display: flex;
flex-direction: column;
width: 30%;
padding-left: 30px;
padding-right: 30px;
border-left: 1px dotted #BFA38A;
height: 85vh;
}
button {
width: 200px;
max-width: 100%;
margin-top: 10px;
margin-bottom: 10px;
height: 35px;
border: 1px solid #BFA38A;
background: transparent;
color: #BFA38A;
border-radius: 5px;
}
button:hover {
cursor: pointer;
background-color: rgba(255,255,255,0.1)
}
.reveal-btn {
border: none;
text-decoration: underline;
margin: 0;
}
.reveal-btn:hover {
color: white;
background-color: transparent;
}
/**
* TODO: Implement a function that clears all the content
* prior to generating new random content
*/
function clearAll() {
}
/**
* TODO:
* - Show a random Meme in the correct location
* - Never show more than 1 meme at a time
*/
function showMeme() {
// Value is a string representing image URL
const randomMemeUrl = getRandomData('memes');
}
/**
* TODO:
* - Show a random joke in the correct location
* - Never show more than 1 joke at a time
*/
function showJoke() {
// Value is a string representing the joke
const randomJokeText = getRandomData('jokes');
}
/**
* TODO:
* - Show a random quote in the correct location
* - Never show more than 1 quote at a time
*/
function showQuote() {
// Value should be in format: { quote: '', author: '' }
const randomQuote = getRandomData('quotes');
}
/**
* TODO:
* - Show a random riddle in the correct location
* - Never show more than 1 riddle at a time
* - Always hide the riddle's answer initially
*/
function showRiddle() {
// Value should be in format: { question: '', answer: '' }
const randomRiddle = getRandomData('riddles');
}
/**
* TODO: Unhide the riddle's answer
* - If there is no riddle shown, alert the user that there is no riddle
* - If there is a riddle shown and an answer shown, alert the user
* that the answer is already revealed
* - If there is a riddle shown but no answer, unhide the answer!
*/
function revealAnswers() {
}
/**
* This function is used to get random data. Don't worry about how it works, just know how to use it. Usage is pre-filled in the functions above already, but here's an explanation of the function anyways.
*
* Valid arguments:
*
* 'memes', 'jokes', 'quotes', 'riddles'
*
* Return values:
*
* For meme data:
* A string representing an image url
*
* For joke data:
* A string representing the joke
*
* For quote data:
* An object - { quote: '', author: '' }
*
* For riddle data:
* An object - { question: '', answer: '' }
*
* Example usage: getRandomData('quotes');
*/
function getRandomData(type) {
return data[type][rn(data[type].length)];
}
// ----------------------------------------------------
// NO NEED TO CHANGE ANYTHING BELOW but...
// feel free to add/remove items from these lists to customize
// your results
// ----------------------------------------------------
// Source: https://www.thecoderpedia.com/blog/programming-memes/, Reddit
const memes = ['https://i.redd.it/a0v87gwzoge61.jpg', 'https://i.redd.it/q29egav34ee61.jpg', 'https://i.redd.it/iij16swxjie61.jpg', 'https://i.redd.it/vek7dm2hrge61.jpg', 'https://www.testbytes.net/wp-content/uploads/2019/06/Untitled-8.png', 'https://miro.medium.com/max/1000/0*Ua695vjzFHV6VNOX.png', 'https://pbs.twimg.com/media/EKkPagPXkAA__Qo.jpg', 'https://code-love.com/wp-content/uploads/2019/03/download.jpeg', 'https://www.thecoderpedia.com/wp-content/uploads/2020/06/Programming-Memes-Programmer-while-sleeping.jpg', 'https://www.thecoderpedia.com/wp-content/uploads/2020/06/Programming-Memes-Evolution-of-Memory-Storage-1024x996.jpg', 'https://www.thecoderpedia.com/wp-content/uploads/2020/06/Programming-Memes-Error-in-Code-896x1024.jpg', 'https://www.thecoderpedia.com/wp-content/uploads/2020/06/Coding-Meme-Code-Comments-be-Like-925x1024.jpg', 'https://www.thecoderpedia.com/wp-content/uploads/2020/06/Internet-Explorer-Joke-915x1024.jpg'];
// Sourced from: http://www.devtopics.com/best-programming-jokes/
const jokes = ['This statement', 'Eight bytes walk into a bar. The bartender asks, “Can I get you anything?” “Yeah,” reply the bytes. “Make us a double.”', 'There are only 10 kinds of people in this world: those who know binary and those who don’t.', 'All programmers are playwrights, and all computers are lousy actors.', 'Have you heard about the new Cray super computer? It’s so fast, it executes an infinite loop in 6 seconds.', 'The generation of random numbers is too important to be left to chance.', 'Debugging: Removing the needles from the haystack.', '“Debugging” is like being the detective in a crime drama where you are also the murderer.', 'There are two ways to write error-free programs; only the third one works.', 'The best thing about a Boolean is even if you are wrong, you are only off by a bit.'];
// source: https://www.goodreads.com/quotes/tag/programming
const quotes = [
{ quote: 'Programs must be written for people to read, and only incidentally for machines to execute.', author: 'Harold Abelson'},
{ quote: 'Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.', author: 'Rick Cook' },
{ quote: 'Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live', author: 'John Woods' },
{ quote: 'Any fool can write code that a computer can understand. Good programmers write code that humans can understand.', author: 'Martin Fowler' },
{ quote: 'Truth can only be found in one place: the code.', author: 'Robert C. Martin' },
{ quote: 'That\'s the thing about people who think they hate computers. What they really hate is lousy programmers.', author: 'Larry Niven' },
{ quote: 'You\'ve baked a really lovely cake, but then you\'ve used dog shit for frosting.', author: 'Steve Jobs' },
{ quote: 'A language that doesn\'t affect the way you think about programming is not worth knowing.', author: 'Alan J. Perlis' },
{ quote: 'The most disastrous thing that you can ever learn is your first programming language.', author: 'Alan Kay' },
{ quote: 'The computer programmer is a creator of universes for which he alone is the lawgiver. No playwright, no stage director, no emperor, however powerful, has ever exercised such absolute authority to arrange a stage or field of battle and to command such unswervingly dutiful actors or troops.', author: 'Joseph Weizenbaum' },
{ quote: 'Everyone knows that debugging is twice as hard as writing a program in the first place. So if you\'re as clever as you can be when you write it, how will you ever debug it?', author: 'Brian Kernighan' },
{ quote: 'No matter which field of work you want to go in, it is of great importance to learn at least one programming language.', author: 'Ram Ray' },
];
// Source: https://www.rd.com/list/challenging-riddles/
const riddles = [
{ question: 'I speak without a mouth and hear without ears. I have no body, but I come alive with wind. What am I?', answer: 'An echo' },
{ question: 'You measure my life in hours and I serve you by expiring. I’m quick when I’m thin and slow when I’m fat. The wind is my enemy. ', answer: 'A Candle' },
{ question: 'I have cities, but no houses. I have mountains, but no trees. I have water, but no fish. What am I? ', answer: 'A Map' },
{ question: 'What is seen in the middle of March and April that can’t be seen at the beginning or end of either month?', answer: 'The letter "R"' },
{ question: 'You see a boat filled with people. It has not sunk, but when you look again you don’t see a single person on the boat. Why?', answer: 'All the people were married' },
{ question: 'What word in the English language does the following: the first two letters signify a male, the first three letters signify a female, the first four letters signify a great, while the entire world signifies a great woman. What is the word?', answer: 'Heroine' }
];
// Just a little helper function
function rn(len) {
return Math.floor(Math.random() * len);
}
const data = {
memes,
jokes,
quotes,
riddles
};
Also see: Tab Triggers